BuildMessage() 공개 메소드

Constructs the final message from the specified template.
public BuildMessage ( string messageTemplate ) : string
messageTemplate string Message template
리턴 string
        public void AddEqualToDataAttr(IEnumerable<PropertyValidatorResult> propertyValidators, HtmlTag htmlTag, RequestData request)
        {
            var result = propertyValidators.FirstOrDefault(x => x.PropertyValidator is EqualValidator);
            if (result != null)
            {
                var equal = result.PropertyValidator.As<EqualValidator>();
                MessageFormatter formatter = new MessageFormatter()
                    .AppendPropertyName(result.DisplayName)
                    .AppendArgument("ComparisonValue", equal.ValueToCompare);

                string message = formatter.BuildMessage(equal.ErrorMessageSource.GetString());

                if (_msUnobtrusive)
                {
                    htmlTag.Data("val", true);
                    htmlTag.Data("val-equalto", message);
                    if (request.Accessor.PropertyNames.Length > 1)
                        htmlTag.Data("val-equalto-other", request.Id.Replace("_" + request.Accessor.Name, "") + "_" + equal.MemberToCompare.Name);
                    else
                        htmlTag.Data("val-equalto-other", "*." + equal.MemberToCompare.Name);
                }
                else
                {
                    htmlTag.Data("msg-equalto", message);
                    if (request.Accessor.PropertyNames.Length > 1)
                        htmlTag.Data("rule-equalto", "#" + request.Id.Replace("_" + request.Accessor.Name, "") + "_" + equal.MemberToCompare.Name);
                    else
                        htmlTag.Data("rule-equalto", "#" + equal.MemberToCompare.Name);
                }
            }
        }
        public override IEnumerable<ModelClientValidationRule> GetClientValidationRules()
        {
            if (!ShouldGenerateClientSideRules())
                yield break;

            var formatter = new MessageFormatter().AppendPropertyName(Rule.PropertyName);
            string message = formatter.BuildMessage(RemoteValidator.ErrorMessageSource.GetString());

            yield return new ModelClientValidationRemoteRule(message, RemoteValidator.Url, RemoteValidator.HttpMethod, RemoteValidator.AdditionalFields);
        }
        public override IEnumerable<ModelClientValidationRule> GetClientValidationRules()
        {
            if (!ShouldGenerateClientSideRules()) yield break;

            var formatter = new MessageFormatter().AppendPropertyName(Rule.PropertyName);
            string message = formatter.BuildMessage(Validator.ErrorMessageSource.GetString());
            var rule = new ModelClientValidationRule
            {
                ValidationType = "notequal",
                ErrorMessage = message
            };
            rule.ValidationParameters["field"] = String.Format("#{0}", ((NotEqualValidator)Validator).MemberToCompare.Name);
            yield return rule;
        }
        public override IEnumerable<ModelClientValidationRule> GetClientValidationRules()
        {
            if (!ShouldGenerateClientSideRules()) yield break;

            var formatter = new MessageFormatter().AppendPropertyName(Rule.GetDisplayName());
            string message = formatter.BuildMessage(Validator.ErrorMessageSource.GetString());
            var clientRule = new ModelClientValidationRule
            {
                ValidationType = "greaterthanorequal",
                ErrorMessage = message,
            };
            clientRule.ValidationParameters.Add("valuetocompare", ((GreaterThanOrEqualValidator)Validator).ValueToCompare);

            yield return clientRule;
        }
        public override IEnumerable<ModelClientValidationRule> GetClientValidationRules()
        {
            if (!this.ShouldGenerateClientSideRules())
                yield break;

            var formatter = new MessageFormatter().AppendPropertyName(Rule.PropertyName);
            string message = formatter.BuildMessage(Validator.ErrorMessageSource.GetString());

            var rule = new ModelClientValidationRule
            {
                ValidationType = "remote",
                ErrorMessage = message
            };
            rule.ValidationParameters.Add("url", "/api/validation/uniqueemail");

            yield return rule;
        }
        public override IEnumerable<ModelClientValidationRule> GetClientValidationRules()
        {
            if (!ShouldGenerateClientSideRules()) yield break;

            var validator = Validator as NotMatchesPropertyValidator;

            var formatter = new MessageFormatter().AppendPropertyName(Rule.GetDisplayName());
            string errorMessage = formatter.BuildMessage(validator.ErrorMessageSource.GetString());

            var rule = new ModelClientValidationRule
            {
                ErrorMessage = errorMessage,
                ValidationType = "nomatchregex"
            };
            rule.ValidationParameters.Add("nomatchpattern", validator.Expression);
            yield return rule;
        }
 public static string GetMessage(RequestData requestData, PropertyValidatorResult propertyValidator)
 {
     MessageFormatter formatter = new MessageFormatter().AppendPropertyName(propertyValidator.DisplayName);
     string message = formatter.BuildMessage(propertyValidator.PropertyValidator.ErrorMessageSource.GetString());
     return message;
 }
 /// <summary>
 /// Get a error message for a property
 /// </summary>
 /// <param name="propertyValidator">PropertyValidator to get for</param>
 /// <param name="propertyName">Name of propery</param>
 /// <returns>Formatted string</returns>
 public static string GetErrorMessageFor(this IPropertyValidator propertyValidator, string propertyName)
 {
     var formatter = new MessageFormatter().AppendPropertyName(propertyName);
     var errorMessage = formatter.BuildMessage(propertyValidator.ErrorMessageSource.GetString());
     return errorMessage;
 }