private static void fillFields(ValidationOptions options, IValidationNode node, IServiceLocator services, Accessor accessor)
        {
            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(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() as IValidationNode;

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

            // TODO -- Let's query the validation graph and register the rule alias/validation mode pairs here
            cache.ForEachProperty(type, property =>
            {
                var accessor = new SingleProperty(property);

                fillFields(options, node, services, accessor);
            });

            return options;
        }
        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);
            });

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