abe545 / CodeOnlyStoredProcedures

A library for easily calling Stored Procedures in .NET using only code (no xml or gui).
MIT License
4 stars 3 forks source link

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

Open abe545 opened 8 years ago

abe545 commented 8 years ago

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; }
}