Exemplo n.º 1
0
        private static void fillFields(ValidationOptions options, IValidationNode node, IServiceLocator services, Accessor accessor, Type type)
        {
            var mode = node.DetermineMode(services, accessor);
            var field = new FieldOptions
            {
                field = accessor.Name,
                mode = mode.Mode
            };

            var graph = services.GetInstance<ValidationGraph>();
            var rules = graph.FieldRulesFor(type, accessor);
            var ruleOptions = new List<FieldRuleOptions>();

            rules.Each(rule =>
            {
                var ruleMode = rule.Mode ?? mode;
                ruleOptions.Add(new FieldRuleOptions
                {
                    rule = RuleAliases.AliasFor(rule),
                    mode = ruleMode.Mode
                });
            });

            field.rules = ruleOptions.ToArray();

            options._fields.Add(field);
        }
Exemplo n.º 2
0
        public static ValidationOptions For(FormRequest request)
        {
            var services = request.Services;
            var type = services.GetInstance<ITypeResolver>().ResolveType(request.Input);
            var cache = services.GetInstance<ITypeDescriptorCache>();
            var options = new ValidationOptions();
            var node = request.Chain.ValidationNode();

            if (node == null)
            {
                return options;
            }

            options._elementTimeout = node.ElementTimeout;

            cache.ForEachProperty(type, property =>
            {
                var accessor = new SingleProperty(property);

                fillFields(options, node, services, accessor, request.Input == null ? property.DeclaringType : request.Input.GetType());
            });

            return options;
        }
Exemplo n.º 3
0
 protected bool Equals(ValidationOptions other)
 {
     return(_fields.SequenceEqual(other._fields));
 }
Exemplo n.º 4
0
 protected bool Equals(ValidationOptions other)
 {
     return _fields.SequenceEqual(other._fields);
 }