public ValidateOptionsResult Validate() { if (!ProfileModelType.IsClass || ProfileModelType.IsAbstract || ProfileModelType.IsGenericType) { return(ValidateOptionsResult.Fail( $"Profile model type '{ProfileModelType.FullName}' must be non-abstract, non-generic class")); } var props = ProfileModelType.GetProperties(); if (props.Length == 0) { return(ValidateOptionsResult.Fail( $"Profile model type '{ProfileModelType.FullName}' must contain at least one public property with read/write access")); } var propertiesCount = 0; foreach (var propertyInfo in props) { if (propertyInfo.DeclaringType != null && (propertyInfo.PropertyType.IsPrimitive || propertyInfo.PropertyType == typeof(string) || propertyInfo.PropertyType == typeof(DateTime))) { if (!propertyInfo.CanWrite) { Console.Out.WriteLine($"{propertyInfo.Name} has no setter method and will be skipped"); } else { propertiesCount++; } continue; } if (propertyInfo.GetCustomAttributes <OwnIdFieldAttribute>().Any()) { return(ValidateOptionsResult.Fail($"{propertyInfo.Name} has unsupported type")); } Console.Out.WriteLine($"{propertyInfo.Name} has unsupported type and will be skipped"); } if (propertiesCount == 0) { return(ValidateOptionsResult.Fail( $"Profile model type '{ProfileModelType.FullName}' must have at least one property with setter")); } if (propertiesCount > 50) { return(ValidateOptionsResult.Fail( $"Profile model type '{ProfileModelType.FullName}' must contain no more than 50 public properties with read/write access. It contain {propertiesCount}")); } return(ValidateOptionsResult.Success); }
public void BuildMetadata() { ProfileFieldMetadata = ProfileModelType .GetProperties().Select(GetField).ToList(); }