Hishop.Components.Validation/Validators/ObjectCollectionValidatorAttribute.cs

(完整代码) 1KB

namespace Hishop.Components.Validation.Validators
{
    using Hishop.Components.Validation;
    using System;

    [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method | AttributeTargets.Class, AllowMultiple=true, Inherited=false)]
    public sealed class ObjectCollectionValidatorAttribute : ValidatorAttribute
    {
        private string targetRuleset;
        private Type targetType;

        public ObjectCollectionValidatorAttribute(Type targetType) : this(targetType, string.Empty)
        {
        }

        public ObjectCollectionValidatorAttribute(Type targetType, string targetRuleset)
        {
            if (targetType == null)
            {
                throw new ArgumentNullException("targetType");
            }
            if (targetRuleset == null)
            {
                throw new ArgumentNullException("targetRuleset");
            }
            this.targetType = targetType;
            this.targetRuleset = targetRuleset;
        }

        protected override Validator DoCreateValidator(Type targetType)
        {
            return new ObjectCollectionValidator(this.targetType, this.targetRuleset);
        }
    }
}

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

AI 解读 AI

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

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