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


C# IValidator.GetType方法代码示例

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


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

示例1: DoEmit

 /// <summary>
 /// Emit implementation starting point
 /// </summary>
 /// <param name="v">The v.</param>
 /// <param name="sb">The sb.</param>
 /// <returns></returns>
 protected StringBuilder DoEmit(IValidator v, StringBuilder sb)
 {
     if (v.GetType().IsGenericType && typeof(ValidationSite<,>).IsAssignableFrom(v.GetType().GetGenericTypeDefinition()))
         return EmitSites(v, sb);
     else
         return EmitNamespace(v, sb);
 }
开发者ID:jijo-paulose,项目名称:bistro-framework,代码行数:13,代码来源:JSEmitter.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: 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

示例5: GetValidator

        /// <summary>
        /// Gets the validator. If the field is <c>null</c>, it will query the service locator.
        /// </summary>
        /// <returns>IValidator.</returns>
        private IValidator GetValidator()
        {
            if (_validator == null)
            {
                if (!_hasRetrievedValidatorOnce)
                {
                    var dependencyResolver = this.GetDependencyResolver();
                    var validatorProvider = dependencyResolver.TryResolve<IValidatorProvider>();
                    if (validatorProvider != null)
                    {
                        _validator = validatorProvider.GetValidator(GetType());
                        if (_validator != null)
                        {
                            Log.Debug("Found validator '{0}' for view model '{1}' via the registered IValidatorProvider", _validator.GetType().FullName, GetType().FullName);
                        }
                    }

                    _hasRetrievedValidatorOnce = true;
                }
            }

            return _validator;
        }
开发者ID:justdude,项目名称:DbExport,代码行数:27,代码来源:ModelBase.validation.cs

示例6: AddValidation

        /// <summary>
        /// Adds a new validation.
        /// </summary>
        /// <param name="source">The source that will provide the value to be validated.</param>
        /// <param name="validator">The <see cref="IValidator"/> that will validate the value.</param>
        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="validator"/> is null.</exception>
        public void AddValidation(string source, IValidator validator)
        {
            if (string.IsNullOrEmpty(source))
                throw new ArgumentNullException("source");

            if ((object)validator == null)
                throw new ArgumentNullException("validator");

            m_validations.Add(string.Format("{0}+{1}", source, validator.GetType().Name), validator);
        }
开发者ID:rmc00,项目名称:gsf,代码行数:16,代码来源:ValidationService.cs

示例7: ChildCollectionValidatorAdaptor

 public ChildCollectionValidatorAdaptor(IValidator childValidator)
 {
     this.childValidatorProvider = (_) => childValidator;
     this.childValidatorType = childValidator.GetType();
 }
开发者ID:GamerD,项目名称:FluentValidation,代码行数:5,代码来源:ChildCollectionValidatorAdaptor.cs

示例8: GetSimpleTypeName

        /// <summary>
        /// Gets the simple name of the type.
        /// </summary>
        /// <param name="child">The child.</param>
        /// <returns></returns>
        private string GetSimpleTypeName(IValidator child)
        {
            var name = child.GetType().FullName;
            var ind = name.IndexOf('`');

            if (ind > -1)
                return name.Substring(0, ind);

            return name;
        }
开发者ID:jijo-paulose,项目名称:bistro-framework,代码行数:15,代码来源:JSEmitter.cs


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