Пример #1
0
        /// <summary>
        /// Registers the validator for.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity">The entity.</param>
        /// <param name="validator">The validator.</param>
        public static void RegisterValidatorFor <T>(IValidator <T> validator, ValidatorContext context)
            where T : IValidatable <T>
        {
            ValidatorKey key = new ValidatorKey();

            key.EntityType       = typeof(T);
            key.ValidatorContext = context;
            validators.Add(string.Format(KEY, key.EntityType.ToString(),
                                         key.ValidatorContext.ToString()), validator);
        }
Пример #2
0
        /// <summary>
        /// Gets the validator for.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public static IValidator <T> GetValidatorFor <T>(T entity, ValidatorContext context)
            where T : IValidatable <T>
        {
            ValidatorKey key = new ValidatorKey();

            key.EntityType       = typeof(T);
            key.ValidatorContext = context;

            return(validators[string.Format(KEY, key.EntityType.ToString(),
                                            key.ValidatorContext.ToString())] as IValidator <T>);
        }