Less allocating IdentityResult.Failed
overload
#42962
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-identity
Includes: Identity and providers
Background and Motivation
IdentityResult
provides useful factoryFailed
method for creating failedIdentityResult
, however it allocates array due to it acceptingparams IdentityError[] errors
as argument, even if user passes only 1 error.My proposal is to add overload to
Failed
method that will accept oneIdentityError
that will not allocate array in such case.Proposed API
namespace Microsoft.AspNetCore.Identity; public class IdentityResult { /* Existing overload public static IdentityResult Failed(params IdentityError[] errors); */ + public static IdentityResult Failed(IdentityError error); }
Usage Examples
From user perspective nothing will change, the same method will be called, in the same way, unless they created
params
array explicitly;Alternative Designs
Create overload accepting
params Span<IdentityError>
when/if dotnet/csharplang#1757 is implemented.Risks
We would need to ensure that behavior of new overload is consistent with current overload, since after recompilation compiler will pick overload without params array, for cases when user calls
Failed
method with single error passed as argument. And behavior won't change unexpectedly for developer.The text was updated successfully, but these errors were encountered: