/// <summary>
 /// Specifies a custom error message resource to use when validation fails.
 /// </summary>
 /// <param name="rule">The current rule</param>
 /// <param name="resourceSelector">The resource to use as an expression, eg () => Messages.MyResource</param>
 /// <param name="formatArgs">Custom message format args</param>
 /// <returns></returns>
 public static IRuleBuilderOptions <T, TProperty> WithLocalizedMessage <T, TProperty>(this IRuleBuilderOptions <T, TProperty> rule, Expression <Func <string> > resourceSelector, params Func <T, object>[] formatArgs)
 {
     // We use the StaticResourceAccessorBuilder here because we don't want calls to WithLocalizedMessage to be overriden by the ResourceProviderType.
     return(rule.WithLocalizedMessage(resourceSelector, new StaticResourceAccessorBuilder())
            .Configure(cfg => {
         formatArgs
         .Select(func => new Func <object, object, object>((instance, value) => func((T)instance)))
         .ForEach(cfg.CurrentValidator.CustomMessageFormatArguments.Add);
     }));
 }
 /// <summary>
 /// Specifies a custom error message resource to use when validation fails.
 /// </summary>
 /// <param name="rule">The current rule</param>
 /// <param name="resourceSelector">The resource to use as an expression, eg () => Messages.MyResource</param>
 /// <returns></returns>
 public static IRuleBuilderOptions <T, TProperty> WithLocalizedMessage <T, TProperty>(this IRuleBuilderOptions <T, TProperty> rule, Expression <Func <string> > resourceSelector)
 {
     // We use the StaticResourceAccessorBuilder here because we don't want calls to WithLocalizedMessage to be overriden by the ResourceProviderType.
     return(rule.WithLocalizedMessage(resourceSelector, new StaticResourceAccessorBuilder()));
 }
        /// <summary>
        /// Specifies a custom error message resource to use when validation fails.
        /// </summary>
        /// <param name="rule">The current rule</param>
        /// <param name="resourceSelector">The resource to use as an expression, eg () => Messages.MyResource</param>
        /// <param name="formatArgs">Custom message format args</param>
        /// <returns></returns>
        public static IRuleBuilderOptions <T, TProperty> WithLocalizedMessage <T, TProperty>(this IRuleBuilderOptions <T, TProperty> rule, Expression <Func <string> > resourceSelector, params object[] formatArgs)
        {
            var funcs = ConvertArrayOfObjectsToArrayOfDelegates <T>(formatArgs);

            return(rule.WithLocalizedMessage(resourceSelector, funcs));
        }
Beispiel #4
0
        public static IRuleBuilderOptions <T, TProperty> WithLocalizedMessage <T, TProperty>(this IRuleBuilderOptions <T, TProperty> rule, Type resourceType, string resourceName, params object[] formatArgs)
        {
            var funcs = DefaultValidatorOptions.ConvertArrayOfObjectsToArrayOfDelegates <T>(formatArgs);

            return(rule.WithLocalizedMessage(resourceType, resourceName, funcs));
        }