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; }
}
It would make certain scenarios much easier. It could work similar to the following: