コード例 #1
0
 /// <summary>
 /// Validate
 /// </summary>
 /// <param name="instance"></param>
 /// <param name="strategy"></param>
 /// <typeparam name="TObject"></typeparam>
 /// <returns></returns>
 public static ValidationResultCollection Validate <TObject>(TObject instance,
                                                             IValidateStrategy <TObject> strategy)
     where TObject : class, IValidatable <TObject>
 {
     instance.AddStrategy(strategy);
     return(instance.Validate());
 }
コード例 #2
0
 /// <summary>
 /// Add strategy
 /// </summary>
 /// <param name="strategy"></param>
 /// <exception cref="ArgumentNullException"></exception>
 public void AddStrategy(IValidateStrategy <TObject> strategy)
 {
     if (strategy == null)
     {
         throw new ArgumentNullException(nameof(strategy));
     }
     if (ValidateStrategyList.Any(x => x.StrategyName == strategy.StrategyName))
     {
         return;
     }
     ValidateStrategyList.Add(strategy);
 }
コード例 #3
0
        /// <summary>
        /// Creates a new property validator strategy for the specified type.
        /// </summary>
        /// <param name="validatorName">The name of the validator such as "Required".</param>
        /// <param name="typeName"></param>
        /// <returns></returns>
        public IValidateStrategy NewPropertyValidator(string validatorName, string typeName)
        {
            IValidateStrategy strategy = null;

            using (LogGroup logGroup = LogGroup.StartDebug("Creating a new validator strategy."))
            {
                CheckType(typeName);

                LogWriter.Debug("Type name: " + typeName);

                strategy = Strategies["Validate_" + validatorName, typeName]
                           .New <IValidateStrategy>(typeName);
            }

            return(strategy);
        }
コード例 #4
0
 /// <summary>
 /// 添加验证策略
 /// </summary>
 /// <param name="strategy">验证策略</param>
 public void AddStrategy(IValidateStrategy <TObject> strategy) => _validationContext.AddStrategy(strategy);
コード例 #5
0
        static public IValidateStrategy New(IEntity entity)
        {
            IValidateStrategy strategy = StrategyState.Strategies.Creator.NewValidator(entity.GetType());

            return(strategy);
        }