Example #1
0
        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());
        }
Example #2
0
 public TypeValidator(Type type, BuilderContext <TState> context)
 {
     Type        = type;
     Properties  = GetPropertyValidators(type, context);
     Constraints = GetConstraints(type, context);
 }
Example #3
0
        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());
        }
Example #4
0
 public static PropertyValidator <TState> Create(PropertyInfo property, BuilderContext <TState> context)
 {
     if (!property.HasGetMethod())
     {
         return(default);