/// <summary>
        /// Verify a member of the entity. <br />
        /// 成员验证入口
        /// </summary>
        /// <param name="expression"></param>
        /// <param name="memberValue"></param>
        /// <typeparam name="TVal"></typeparam>
        /// <returns></returns>
        public virtual VerifyResult VerifyOne <TVal>(Expression <Func <T, TVal> > expression, TVal memberValue)
        {
            var memberName     = PropertySelector.GetPropertyName(expression);
            var memberContract = VerifiableObjectContractManager.Resolve <T>()?.GetMemberContract(memberName);

            if (memberContract is null)
            {
                return(VerifyResult.MemberIsNotExists(memberName));
            }
            var memberContext = VerifiableMemberContext.Create(memberValue, memberContract);

            return(VerifyOneImpl(memberContext));
        }
        /// <summary>
        /// Verify a member of the entity. <br />
        /// 成员验证入口
        /// </summary>
        /// <param name="expression"></param>
        /// <param name="memberValue"></param>
        /// <param name="keyValueCollection"></param>
        /// <typeparam name="TVal"></typeparam>
        /// <returns></returns>
        public virtual VerifyResult VerifyOneWithDictionary <TVal>(Expression <Func <T, TVal> > expression, TVal memberValue, IDictionary <string, object> keyValueCollection)
        {
            var parentContract = VerifiableObjectContractManager.Resolve <T>();
            var memberName     = PropertySelector.GetPropertyName(expression);
            var memberContract = parentContract?.GetMemberContract(memberName);

            if (memberContract is null)
            {
                return(VerifyResult.MemberIsNotExists(memberName));
            }
            var memberContext = VerifiableMemberContext.Create(memberValue, memberContract, parentContract.WithDictionary(keyValueCollection));

            return(VerifyOneImpl(memberContext));
        }
        /// <summary>
        /// Verify a member of the entity. <br />
        /// 成员验证入口
        /// </summary>
        /// <param name="expression"></param>
        /// <param name="memberValue"></param>
        /// <typeparam name="TVal"></typeparam>
        /// <returns></returns>
        public VerifyResult VerifyOne <TVal>(Expression <Func <T, TVal> > expression, TVal memberValue)
        {
            if (expression is null)
            {
                return(_options.ReturnNullReferenceOrSuccess());
            }
            var memberName     = PropertySelector.GetPropertyName(expression);
            var memberContract = VerifiableObjectContractManager.Resolve <T>()?.GetMemberContract(memberName);

            if (memberContract is null)
            {
                return(VerifyResult.MemberIsNotExists(memberName));
            }
            return(VerifyOneInternal(VerifiableMemberContext.Create(memberValue, memberContract)));
        }
        /// <summary>
        /// Verify a member of the entity. <br />
        /// 成员验证入口
        /// </summary>
        /// <param name="expression"></param>
        /// <param name="memberValue"></param>
        /// <param name="keyValueCollection"></param>
        /// <typeparam name="TVal"></typeparam>
        /// <returns></returns>
        public VerifyResult VerifyOneWithDictionary <TVal>(Expression <Func <T, TVal> > expression, TVal memberValue, IDictionary <string, object> keyValueCollection)
        {
            if (expression is null)
            {
                return(_options.ReturnNullReferenceOrSuccess());
            }
            var parentContract = VerifiableObjectContractManager.Resolve <T>();
            var memberName     = PropertySelector.GetPropertyName(expression);
            var memberContract = parentContract?.GetMemberContract(memberName);

            if (memberContract is null)
            {
                return(VerifyResult.MemberIsNotExists(memberName));
            }
            return(VerifyOneInternal(VerifiableMemberContext.Create(memberValue, memberContract, parentContract.WithDictionary(keyValueCollection))));
        }
Ejemplo n.º 5
0
        public IValueFluentValidationRegistrar <T, TVal> ForMember <TVal>(Expression <Func <T, TVal> > expression, VerifyRuleMode mode = VerifyRuleMode.Append)
        {
            if (expression is null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            var memberName    = PropertySelector.GetPropertyName(expression);
            var valueContract = _verifiableObjectContract.GetMemberContract(memberName);

            if (valueContract is null)
            {
                throw new InvalidOperationException($"Cannot match such Member named '{memberName}'.");
            }

            return(new ValueValidationRegistrar <T, TVal>(valueContract, Rules, mode, this, _parentRegistrar));
        }