From b97b688a5287ce9ed5412c364c55fa0e660b608e Mon Sep 17 00:00:00 2001 From: N1K0232 Date: Sun, 1 Oct 2023 11:26:48 +0200 Subject: [PATCH] Add Union method to add a list of string of the same claim type to my claims collection --- src/SimpleAuthentication.Abstractions/ClaimExtensions.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/SimpleAuthentication.Abstractions/ClaimExtensions.cs b/src/SimpleAuthentication.Abstractions/ClaimExtensions.cs index e56c257..ee7ca7d 100644 --- a/src/SimpleAuthentication.Abstractions/ClaimExtensions.cs +++ b/src/SimpleAuthentication.Abstractions/ClaimExtensions.cs @@ -101,6 +101,15 @@ public static bool HasClaim(this ClaimsPrincipal user, string type) return hasClaim; } + /// + /// Adds a collection of string values in the list of claims with the same claim type + /// + /// The claims list + /// The type of the claims that will be added + /// The collection of values + public static IList Union(this IList claims, string type, IEnumerable values) + => claims.Union(values.Select(value => new Claim(type, value))).ToList(); + private static T? Convert(string value) => (T?)TypeDescriptor.GetConverter(typeof(T)).ConvertFromInvariantString(value); }