Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
abe545 opened this issue Apr 4, 2016 · 0 comments
Open

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

abe545 opened this issue Apr 4, 2016 · 0 comments
Assignees

Comments

@abe545
Copy link
Owner

abe545 commented Apr 4, 2016

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; }
}
@abe545 abe545 self-assigned this Jul 31, 2016
@abe545 abe545 added this to the 2.3.0 milestone Jul 31, 2016
@abe545 abe545 removed this from the 2.3.0 milestone Aug 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant