private static ReadonlyArray <IConstraint <TState> > GetConstraints(Type type, BuilderContext <TState> context) { var array = new ArrayBuilder <IConstraint <TState> >(context.Builder.Constraints.Count); foreach (var builder in context.Builder.Constraints) { if (builder.Create(type, context) is IConstraint <TState> constraint) { array.Add(constraint); } } return(array.Build()); }
public TypeValidator(Type type, BuilderContext <TState> context) { Type = type; Properties = GetPropertyValidators(type, context); Constraints = GetConstraints(type, context); }
private static ReadonlyArray <PropertyValidator <TState> > GetPropertyValidators(Type type, BuilderContext <TState> context) { var properties = type.GetInstanceProperties(); var array = new ArrayBuilder <PropertyValidator <TState> >(properties.Length); foreach (var property in properties) { if (PropertyValidator <TState> .Create(property, context) is PropertyValidator <TState> validator) { array.Add(validator); } } return(array.Build()); }
public static PropertyValidator <TState> Create(PropertyInfo property, BuilderContext <TState> context) { if (!property.HasGetMethod()) { return(default);