AKlaus / DomainResult

Tiny package for decoupling domain operation results from IActionResult and IResult types of ASP.NET Web API
Apache License 2.0
53 stars 3 forks source link

Add `IDomainResult.FailIfNull` methods (syntactic sugar) #50

Closed AKlaus closed 1 year ago

AKlaus commented 1 year ago

Inspired by ArgumentNullException.ThrowIfNull() method in .NET 6 (docs)

Add syntactic sugar static methods to return Failed status if the specified parameter is null – all to save time writing a null check if condition.

Suggested methods:

AKlaus commented 1 year ago

On second thought, the proposal would reduce understanding of the code and a marginal reduction of code lines.

Helper methods like this don't bring much value and may lead to an analysis paralysis on which method to use:

public static IDomainResult FailedIfNull<T>([NotNull] T? notNullArgument, string? error = null)
  => (notNullArgument is null) ? Failed(error) : Success(notNullArgument);