private static void SetProperty(KeyValuePair<string, PropertyInfo> property, TypedClaimAttribute attr, IEnumerable<Claim> claims, TypedClaims typedClaimsObject) { var selectedClaims = claims.Where(c => c.Type == attr.ClaimType); if (!selectedClaims.Any()) return; var type = property.Value.GetValue(typedClaimsObject, null).GetType().GetGenericArguments()[0]; property.Value.SetValue(typedClaimsObject, SetValue(type, selectedClaims, attr.IsCollection), null); }
private static IEnumerable<KeyValuePair<string, PropertyInfo>> GetProperties(TypedClaims typedClaimsObject) { var settingsType = typedClaimsObject.GetType(); var result = new Dictionary<string, PropertyInfo>(StringComparer.OrdinalIgnoreCase); foreach (var prop in settingsType.GetProperties()) result[prop.Name] = prop; return result; }
internal static void Update(IEnumerable<Claim> claims, TypedClaims typedClaimsObject) { if (claims == null || !claims.Any()) return; var properties = GetProperties(typedClaimsObject); foreach (var p in properties) { var prop = p.Value; var attributes = prop.GetCustomAttributes(true).Where(a => a is TypedClaimAttribute); if (!attributes.Any()) continue; SetProperty(p, (TypedClaimAttribute)attributes.First(), claims, typedClaimsObject); } }
internal static void Update(IEnumerable <Claim> claims, TypedClaims typedClaimsObject) { if (claims == null || !claims.Any()) { return; } var properties = GetProperties(typedClaimsObject); foreach (var p in properties) { var prop = p.Value; var attributes = prop.GetCustomAttributes(true).Where(a => a is TypedClaimAttribute); if (!attributes.Any()) { continue; } SetProperty(p, (TypedClaimAttribute)attributes.First(), claims, typedClaimsObject); } }
private static void SetProperty(KeyValuePair <string, PropertyInfo> property, TypedClaimAttribute attr, IEnumerable <Claim> claims, TypedClaims typedClaimsObject) { var selectedClaims = claims.Where(c => c.Type == attr.ClaimType); if (!selectedClaims.Any()) { return; } var type = property.Value.GetValue(typedClaimsObject, null).GetType().GetGenericArguments()[0]; property.Value.SetValue(typedClaimsObject, SetValue(type, selectedClaims, attr.IsCollection), null); }
private static IEnumerable <KeyValuePair <string, PropertyInfo> > GetProperties(TypedClaims typedClaimsObject) { var settingsType = typedClaimsObject.GetType(); var result = new Dictionary <string, PropertyInfo>(StringComparer.OrdinalIgnoreCase); foreach (var prop in settingsType.GetProperties()) { result[prop.Name] = prop; } return(result); }