当前位置: 首页>>代码示例>>C#>>正文


C# IValidator.CreateDescriptor方法代码示例

本文整理汇总了C#中IValidator.CreateDescriptor方法的典型用法代码示例。如果您正苦于以下问题:C# IValidator.CreateDescriptor方法的具体用法?C# IValidator.CreateDescriptor怎么用?C# IValidator.CreateDescriptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IValidator的用法示例。


在下文中一共展示了IValidator.CreateDescriptor方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetValue

        private void GetValue(IValidator inputValidator, ValidationMetaData metaData, string parentKey)
        {
            var descriptor = inputValidator.CreateDescriptor();
            var members = descriptor.GetMembersWithValidators();
            
            foreach (var member in members)
            {

                var rules = descriptor.GetRulesForMember(member.Key);
                foreach (var rule in rules)
                {
                    foreach (var validator in rule.Validators)
                    {
                        var currentKey = string.IsNullOrEmpty(parentKey) ? member.Key : string.Format("{0}.{1}", parentKey, member.Key.ToCamelCase());
                        if (validator is ChildValidatorAdaptor)
                        {
                            var childValidator = (validator as ChildValidatorAdaptor).Validator;
                            GetValue(childValidator, metaData, currentKey);
                        }
                        else if(validator is IPropertyValidator)
                            GenerateFor(metaData, currentKey, validator as IPropertyValidator);
                    }
                }
            }
        }
开发者ID:sphair,项目名称:Bifrost,代码行数:25,代码来源:ValidationMetaDataGenerator.cs

示例2: GenerateForValidator

        void GenerateForValidator(IValidator inputValidator, TypeMetaData metaData, string parentKey, bool isParentConcept = false, bool isParentModelRule = false)
        {
            var inputValidatorType = inputValidator.GetType();
            var genericArguments = inputValidatorType.BaseType.GetGenericArguments();

            var descriptor = inputValidator.CreateDescriptor();
            var members = descriptor.GetMembersWithValidators();
            
            foreach (var member in members)
            {
                var rules = descriptor.GetRulesForMember(member.Key);
                foreach (var rule in rules)
                {
                    foreach (var validator in rule.Validators)
                    {
                        var isModelRule = member.Key == ModelRule<string>.ModelRulePropertyName;
                        var currentKey = GetKeyForMember(parentKey, isParentConcept, isParentModelRule, member, isModelRule);

                        if (validator is ChildValidatorAdaptor)
                        {
                            GenerateForChildValidator(metaData, genericArguments, member, validator, isModelRule, currentKey);
                        }
                        else if (validator is IPropertyValidator)
                        {
                            GenerateFor(metaData, currentKey, validator);
                        }
                    }
                }
            }
        }
开发者ID:dolittle,项目名称:Bifrost,代码行数:30,代码来源:ValidationMetaDataGenerator.cs

示例3: GetValue

        void GetValue(IValidator inputValidator, ValidationMetaData metaData, string parentKey, bool isParentConcept = false, bool isParentModelRule = false)
        {
            var inputValidatorType = inputValidator.GetType();
#if(NETFX_CORE)
            var genericArguments = inputValidatorType.GetTypeInfo().BaseType.GenericTypeArguments;
#else
            var genericArguments = inputValidatorType.BaseType.GetGenericArguments();
#endif

            var descriptor = inputValidator.CreateDescriptor();
            var members = descriptor.GetMembersWithValidators();
            
            foreach (var member in members)
            {
                var rules = descriptor.GetRulesForMember(member.Key);
                foreach (var rule in rules)
                {
                    foreach (var validator in rule.Validators)
                    {
                        var isModelRule = member.Key == ModelRule<string>.ModelRulePropertyName;
                        var currentKey = string.Empty;
                        if (isParentConcept || isParentModelRule || isModelRule)
                            currentKey = parentKey;
                        else
                            currentKey = string.IsNullOrEmpty(parentKey) ? member.Key : string.Format("{0}.{1}", parentKey, member.Key.ToCamelCase());

                        if (validator is ChildValidatorAdaptor)
                        {
                            var isConcept = false;
                            
                            if (genericArguments.Length == 1)
                            {
                                var type = isModelRule ? genericArguments[0] : GetPropertyInfo(genericArguments[0], member.Key).PropertyType;
                                isConcept = type.IsConcept();
                            }

                            var childValidator = (validator as ChildValidatorAdaptor).Validator;
                            GetValue(childValidator, metaData, currentKey, isConcept, isModelRule);
                        }
                        else if (validator is IPropertyValidator)
                        {
                            GenerateFor(metaData, currentKey, validator as IPropertyValidator);
                        }
                    }
                }
            }
        }
开发者ID:JoB70,项目名称:Bifrost,代码行数:47,代码来源:ValidationMetaDataGenerator.cs

示例4: GenerateFrom

#pragma warning disable 1591 // Xml Comments
        public ValidationMetaData GenerateFrom(IValidator inputValidator)
        {
            var metaData = new ValidationMetaData();
            var descriptor = inputValidator.CreateDescriptor();
            var members = descriptor.GetMembersWithValidators();
            foreach (var member in members)
            {
                var rules = descriptor.GetRulesForMember(member.Key);
                foreach (var rule in rules)
                {
                    foreach (var validator in rule.Validators)
                    {
                        if (validator is IPropertyValidator)
                            GenerateFor(metaData, member.Key, validator as IPropertyValidator);
                    }
                }
            }

            return metaData;
        }
开发者ID:TormodHystad,项目名称:Bifrost,代码行数:21,代码来源:ValidationMetaDataGenerator.cs

示例5: GetValidators

        public static ConstraintsAndMappers GetValidators(IValidator self, Func<IPropertyValidator, Type> getMapperFor)
        {
            if (self == null)
            {
                return new ConstraintsAndMappers(new List<ConstraintsAndMappers.Item>());
            }

            var parameters = self.CreateDescriptor()
                .GetMembersWithValidators()
                .Select(validators =>
                {
                    var constraints = validators
                        .Select(c => new ConstraintsAndMappers.Item.Entry(getMapperFor(c), c))
                        .Where(c => c.RuleGeneratorType != null)
                        .ToList();
                    return new ConstraintsAndMappers.Item(validators.Key, constraints);
                }).Where(p => p.Constraints.Any()).ToList();

            return new ConstraintsAndMappers(parameters);
        }
开发者ID:decojs,项目名称:QvcFluentValidation,代码行数:20,代码来源:FluentConstraintsSteps.cs

示例6: GetValidatorsForProperty

        private IEnumerable<ModelValidator> GetValidatorsForProperty(ModelMetadata metadata, IEnumerable<ModelValidatorProvider> validatorProviders, IValidator validator)
        {
            var modelValidators = new List<ModelValidator>();

            if (validator != null)
            {
                var descriptor = validator.CreateDescriptor();

                var validatorsWithRules = from rule in descriptor.GetRulesForMember(metadata.PropertyName)
                                          let propertyRule = (PropertyRule)rule
                                          let validators = rule.Validators
                                          where validators.Any()
                                          from propertyValidator in validators
                                          let modelValidatorForProperty = GetModelValidator(metadata, validatorProviders, propertyRule, propertyValidator)
                                          where modelValidatorForProperty != null
                                          select modelValidatorForProperty;

                modelValidators.AddRange(validatorsWithRules);
            }

            //if (validator != null && metadata.IsRequired && AddImplicitRequiredValidator)
            //{
            //    bool hasRequiredValidators = modelValidators.Any(x => x.IsRequired);

            //    //If the model is 'Required' then we assume it must have a NotNullValidator.
            //    //This is consistent with the behaviour of the DataAnnotationsModelValidatorProvider
            //    //which silently adds a RequiredAttribute

            //    if (!hasRequiredValidators)
            //    {
            //        modelValidators.Add(CreateNotNullValidatorForProperty(metadata, context));
            //    }
            //}

            return modelValidators;
        }
开发者ID:danludwig,项目名称:danludwig,代码行数:36,代码来源:FluentValidationHttpModelValidatorProvider.cs

示例7: GenerateForValidator

        void GenerateForValidator(
            IValidator inputValidator,
            TypeMetaData metaData,
            string parentKey,
            bool shouldUseParentKey = false)
        {
            var inputValidatorType = inputValidator.GetType();
            var genericArguments = inputValidatorType.BaseType.GetGenericArguments();

            var descriptor = inputValidator.CreateDescriptor();
            var members = descriptor.GetMembersWithValidators();

            foreach (var member in members)
            {
                var isModelRule = member.Key == ModelRule<string>.ModelRulePropertyName || member.Key == string.Empty;
                var currentKey = (shouldUseParentKey || isModelRule) ? parentKey : GetKeyForMember(parentKey, member);
                var isConcept = new Lazy<bool>(() => IsConcept(genericArguments, isModelRule, member));

                foreach (var rule in descriptor.GetRulesForMember(member.Key))
                {
                    foreach (var validator in rule.Validators)
                    {
                        var childValidatorAdaptor = validator as ChildValidatorAdaptor;
                        if (childValidatorAdaptor != null)
                        {
                            var childValidator = childValidatorAdaptor.GetValidator(NullContext);
                            GenerateForValidator(childValidator, metaData, currentKey, isModelRule || isConcept.Value);
                        }
                        else
                        {
                            GenerateFor(metaData, currentKey, validator);
                        }
                    }
                }
            }
        }
开发者ID:ProCoSys,项目名称:Bifrost,代码行数:36,代码来源:ValidationMetaDataGenerator.cs

示例8: GetPropertyValidators

 private IEnumerable<PropertyValidatorResult> GetPropertyValidators(IValidator baseValidator, List<PropertyInfo> properties)
 {
     var desc = baseValidator.CreateDescriptor();
     var validators = GetNestedPropertyValidators(desc, properties, 0).ToList();
     return validators;
 }
开发者ID:schotime,项目名称:SchoStack,代码行数:6,代码来源:FluentValidatorFinder.cs

示例9: GetValidatorsForProperty

        IEnumerable<ModelValidator> GetValidatorsForProperty(ModelMetadata metadata, ControllerContext context, IValidator validator)
        {
            var modelValidators = new List<ModelValidator>();

            if (validator != null) {
                var descriptor = validator.CreateDescriptor();

                var validatorsWithRules = from rule in descriptor.GetRulesForMember(metadata.PropertyName)
                                          let propertyRule = (PropertyRule)rule
                                          // Only want to include rules that allow standalone clientside validation.
                                          let validators = rule.Validators.Where(x => x.SupportsStandaloneValidation)
                                          where validators.Any()
                                          from propertyValidator in validators
                                          select new { validator = propertyValidator, rule = propertyRule };

                foreach(var validatorWithRule in validatorsWithRules) {
                    modelValidators.Add(GetModelValidator(metadata, context, validatorWithRule.rule, validatorWithRule.validator));
                }
            }

            if(metadata.IsRequired && AddImplicitRequiredValidator) {
                bool hasRequiredValidators = modelValidators.Any(x => x.IsRequired);

                //Is the model is 'Required' then we assume it must have a NotNullValidator.
                //This is consistent with the behaviour of the DataAnnotationsModelValidatorProvider
                //which silently adds a RequiredAttribute

                if(! hasRequiredValidators) {
                    modelValidators.Add(CreateNotNullValidatorForProperty(metadata, context));
                }
            }

            return modelValidators;
        }
开发者ID:cjberg,项目名称:FluentValidation,代码行数:34,代码来源:FluentValidationModelValidatorProvider.cs

示例10: GetValidatorsForProperty

        IEnumerable<ModelValidator> GetValidatorsForProperty(ModelMetadata metadata, ControllerContext context, IValidator validator)
        {
            var modelValidators = new List<ModelValidator>();

            if (validator != null) {
                var descriptor = validator.CreateDescriptor();

                var validators = descriptor.GetValidatorsForMember(metadata.PropertyName)
                    .Where(x => x.SupportsStandaloneValidation);

                foreach(var propertyValidator in validators) {
                    modelValidators.Add(GetModelValidator(metadata, context, propertyValidator));
                }
            }

            if(metadata.IsRequired && AddImplicitRequiredValidator) {
                bool hasRequiredValidators = modelValidators.Any(x => x.IsRequired);

                //Is the model is 'Required' then we assume it must have a NotNullValidator.
                //This is consistent with the behaviour of the DataAnnotationsModelValidatorProvider
                //which silently adds a RequiredAttribute

                if(! hasRequiredValidators) {
                    modelValidators.Add(CreateNotNullValidatorForProperty(metadata, context));
                }
            }

            return modelValidators;
        }
开发者ID:rsmolnikov,项目名称:FluentValidation,代码行数:29,代码来源:FluentValidationModelValidatorProvider.cs

示例11: GetValidatorsForProperty

        IEnumerable<ModelValidator> GetValidatorsForProperty(ModelMetadata metadata, ControllerContext context, IValidator validator)
        {
            var modelValidators = new List<ModelValidator>();

            if (validator != null) {
                var descriptor = validator.CreateDescriptor();

                var validators = descriptor.GetValidatorsForMember(metadata.PropertyName);
                    //Equal validator with MemberInfo not support standalone
                    //.Where(x => x.SupportsStandaloneValidation);

                foreach(var propertyValidator in validators) {
                    modelValidators.Add(GetModelValidator(metadata, context, propertyValidator));
                }
            }

            return modelValidators;
        }
开发者ID:rsmolnikov,项目名称:FluentValidation,代码行数:18,代码来源:ExtendedFluentValidationModelValidatorProvider.cs


注:本文中的IValidator.CreateDescriptor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。