Hishop.Components.Validation/PropertyValidationFactory.cs

(开头部分) 6KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

namespace Hishop.Components.Validation
{
    using Hishop.Components.Validation.Properties;
    using System;
    using System.Collections.Generic;
    using System.Reflection;
    using System.Runtime.InteropServices;

    internal static class PropertyValidationFactory
    {
        private static IDictionary<PropertyValidatorCacheKey, Validator> attributeAndDefaultConfigurationPropertyValidatorsCache = new Dictionary<PropertyValidatorCacheKey, Validator>();
        private static object attributeAndDefaultConfigurationPropertyValidatorsCacheLock = new object();
        private static IDictionary<PropertyValidatorCacheKey, Validator> attributeOnlyPropertyValidatorsCache = new Dictionary<PropertyValidatorCacheKey, Validator>();
        private static object attributeOnlyPropertyValidatorsCacheLock = new object();
        private static IDictionary<PropertyValidatorCacheKey, Validator> defaultConfigurationOnlyPropertyValidatorsCache = new Dictionary<PropertyValidatorCacheKey, Validator>();
        private static object defaultConfigurationOnlyPropertyValidatorsCacheLock = new object();

        internal static Validator GetPropertyValidator(Type type, PropertyInfo propertyInfo, string ruleset, MemberAccessValidatorBuilderFactory memberAccessValidatorBuilderFactory)
        {
            Validator validator = null;
            lock (attributeAndDefaultConfigurationPropertyValidatorsCacheLock)
            {
                PropertyValidatorCacheKey key = new PropertyValidatorCacheKey(type, propertyInfo.Name, ruleset);
                if (!attributeAndDefaultConfigurationPropertyValidatorsCache.TryGetValue(key, out validator))
                {
                    validator = GetPropertyValidatorFromAttributes(type, propertyInfo, ruleset, memberAccessValidatorBuilderFactory);
                    attributeAndDefaultConfigurationPropertyValidatorsCache[key] = validator;
                }
            }
            return validator;
        }

        internal static Validator GetPropertyValidator(Type type, PropertyInfo propertyInfo, string ruleset, ValidationSpecificationSource validationSpecificationSource, MemberAccessValidatorBuilderFactory memberAccessValidatorBuilderFactory)
        {
            if (type == null)
            {
                throw new InvalidOperationException(Resources.ExceptionTypeNotFound);
            }
            if (propertyInfo == null)
            {
                throw new InvalidOperationException(Resources.ExceptionPropertyNotFound);
            }
            if (!propertyInfo.CanRead)
            {
                throw new InvalidOperationException(Resources.ExceptionPropertyNotReadable);
            }
            switch (validationSpecificationSource)
            {
                case ValidationSpecificationSource.Attributes:
                    return GetPropertyValidatorFromAttributes(type, propertyInfo, ruleset, memberAccessValidatorBuilderFactory);

                case ValidationSpecificationSource.Both:
                    return GetPropertyValidator(type, propertyInfo, ruleset, memberAccessValidatorBuilderFactory);
            }
            return null;
        }

        internal static Validator GetPropertyValidator(Type type, PropertyInfo propertyInfo, string ruleset, ValidationSpecificationSource validationSpecificationSource, MemberValueAccessBuilder memberValueAccessBuilder)
        {
            return GetPropertyValidator(type, propertyInfo, ruleset, validationSpecificationSource, new MemberAccessValidatorBuilderFactory(memberValueAccessBuilder));
后面还有 72 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。