You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would you consider modifying the Result<T> class to be marked with partial?
I've built up a small little arsenal of extension methods for Result<T> in my codebase (that are probably too specific to hold value in your repo) however sometimes these extension methods would fit better as traditional static methods.
My current example is an attempt to get around a common pattern I find myself using where I need to use an if to return either a Success or a NotFound based on the nullability of a variable:
This works because it turns the Result<T?> (nullable) into a Result<T> (non-nullable), however I'd probably prefer something like this:
namespace Ardalis.Result
{publicpartialclassResult<T>{publicstaticResult<T>SuccessOrNotFound(T?value)=>
value is not null?Result<T>.Success(value):Result<T>.NotFound();}}
By marking Result<T> as partial I'd able to create my own static method without the need to inspect the .Value of a Result<T> in order to return either a Success or NotFound.
Thanks, let me know what you think :)
The text was updated successfully, but these errors were encountered:
Hey,
Would you consider modifying the
Result<T>
class to be marked withpartial
?I've built up a small little arsenal of extension methods for
Result<T>
in my codebase (that are probably too specific to hold value in your repo) however sometimes these extension methods would fit better as traditional static methods.My current example is an attempt to get around a common pattern I find myself using where I need to use an
if
to return either aSuccess
or aNotFound
based on the nullability of a variable:I'm currently getting around this by using a
OrNotFound
extension method:This works because it turns the
Result<T?>
(nullable) into aResult<T>
(non-nullable), however I'd probably prefer something like this:By marking
Result<T>
aspartial
I'd able to create my own static method without the need to inspect the.Value
of aResult<T>
in order to return either aSuccess
orNotFound
.Thanks, let me know what you think :)
The text was updated successfully, but these errors were encountered: