Skip to content

Add ability to specify a default value for an optional result #68

@abe545

Description

@abe545

It would make certain scenarios much easier. It could work similar to the following:

public interface IOptionalResult<T>
{
    T GetDefaultValue();
}

public class OptionalResultAttribute<T> : OptionalResultAttribute, IOptionalResult<T>
{
    public T DefaultValue{ get; set; }

    public T GetDefaultValue() { return DefaultValue; }
}

public class EmptyEnumerableOptionalResult<T> : OptionalResultAttribute, IOptionalResult<IEnumerable<T>>
{
    public IEnumerable<T> GetDefaultValue() { return Enumerable.Empty<T>(); }
}

public class DTO
{
    [EmptyEnumerableOptionalResult<string>]
    public IEnumerable<string> SometimesEmpty { get; set; }
}

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions