-
Notifications
You must be signed in to change notification settings - Fork 80
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Describe the feature
I'm wondering if it makes sense to have a From method that accepts nullable values and performs checks like this:
[ValueObject<string>]
public readonly partial struct SampleId
{
public static SampleId? FromNullable(in string? value)
=> value != null ? SampleId.From(value) : null; // <======= nice to have
}
public class SampleEntity(SampleId id, SampleId? parentEntityId)
{
public SampleId Id { get; set; } = id;
public SampleId? ParentEntityId { get; set; } = parentEntityId;
}
public class SampleEntityBuilder
{
public static SampleEntity Build(string id, string? parentEntityId)
{
return new SampleEntity(
SampleId.From(id),
SampleId.FromNullable(parentEntityId)); // <======= use case here
}
}Am I missing an already existing feature like this?
The use case would be having better in-lined code without the need of explicit checks.
Thanks in advance :)
nwalker-et
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request