public static QueryTypeBuilder <T> ProtectSensitiveInformation <T>(this QueryTypeBuilder <T> queryTypeBuilder) where T : class { foreach (PropertyInfo propertyInfo in typeof(T).GetProperties()) { SensitiveInformationAttribute sensitiveInformationAttribute = propertyInfo.GetCustomAttributes <SensitiveInformationAttribute>().SingleOrDefault(); if (propertyInfo.DeclaringType == typeof(T) && sensitiveInformationAttribute != null) { IMutableProperty mutableProperty = queryTypeBuilder.Property(propertyInfo.Name).Metadata; mutableProperty.SetValueConverter(SensitiveInformationConverter.Create(sensitiveInformationAttribute.KeyName)); } } return(queryTypeBuilder); }
public static ModelBuilder ProtectSensitiveInformation(this ModelBuilder modelBuilder) { foreach (IMutableEntityType mutableEntityType in modelBuilder.Model.GetEntityTypes()) { foreach (IMutableProperty mutableProperty in mutableEntityType.GetProperties()) { SensitiveInformationAttribute sensitiveInformationAttribute = mutableProperty.PropertyInfo?.GetCustomAttributes <SensitiveInformationAttribute>().SingleOrDefault(); if (sensitiveInformationAttribute != null) { mutableProperty.SetMaxLength(FieldSizes.Protected); mutableProperty.SetValueConverter(SensitiveInformationConverter.Create(sensitiveInformationAttribute.KeyName)); } } } return(modelBuilder); }