OneOf
OneOf copied to clipboard
Can we have a parameterless None.Of<T>() method ?
Hi, I'm wondering why there is only a version of None.Of<T>(T t) that takes a parameter ?
I think it would make sense to have that same method without parameter, like this :
public static OneOf.OneOf<T, None> Of<T>() => (OneOf.OneOf<T, None>) new None();
Here is my use case :
public OneOf<Foo, None> FindFoo()
=> aMethodThatReturnsFooOrNull() ?? None.Of<Foo>();
Currently this is how I have to handle this :
public OneOf<Foo, None> FindFoo()
=> aMethodThatReturnsFooOrNull() ?? None.Of<Foo>(null!);
Btw thx for the lib, it is great.
Same here.
We use:
public OneOf<Foo, None> FindFoo()
=> aMethodThatReturnsFooOrNull() ?? None.Of<Foo>(default!);
This would be great:
public OneOf<Foo, None> FindFoo()
=> aMethodThatReturnsFooOrNull() ?? None.Of<Foo>();
Workaround
using OneOf;
using OneOf.Types;
namespace SuD.Domain.Extensions;
public static class NoneExtensions
{
public static OneOf<T, None> Of<T>(this None _) => (OneOf<T, None>)default(None);
}
public OneOf<Foo, None> FindFoo()
=> aMethodThatReturnsFooOrNull() ?? new None().Of<Foo>();
I have been thinking about a static OneOf.Types.Factory class with a None method, then you can do a using static OneOf.Types.Factory and just return None()
On Tue, 10 May 2022, 19:06 emperador-ming, @.***> wrote:
Workaround
using OneOf;
using OneOf.Types;
namespace SuD.Domain.Extensions;
public static class NoneExtensions { public static OneOf<T, None> Of<T>(this None _)
{ return (OneOf<T, None>)default(None); }
}
public OneOf<Foo, None> FindFoo() => aMethodThatReturnsFooOrNull() ?? new None().Of<Foo>();
— Reply to this email directly, view it on GitHub https://github.com/mcintyre321/OneOf/issues/113#issuecomment-1122709944, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACDJ6XHAVQ64KHWQ3VBTR3VJKQTVANCNFSM5REHIOYA . You are receiving this because you are subscribed to this thread.Message ID: @.***>