yavsc/src/Yavsc.Abstract/Attributes/Validation/YaRegularExpression.cs

23 lines
801 B
C#
Raw Normal View History

2018-03-26 19:27:29 +02:00
2019-06-16 01:10:52 +01:00
using System;
using System.Reflection;
2017-10-04 23:53:47 +02:00
namespace Yavsc.Attributes.Validation
{
public class YaRegularExpression : System.ComponentModel.DataAnnotations.RegularExpressionAttribute {
public YaRegularExpression(string pattern): base (pattern)
{
this.ErrorMessage = "RegularExpression: "+ pattern;
2017-10-04 23:53:47 +02:00
}
public override string FormatErrorMessage(string name)
{
if (ErrorMessageResourceType==null || string.IsNullOrEmpty(ErrorMessageResourceName))
return ErrorMessage;
2019-06-16 01:10:52 +01:00
var prop = this.ErrorMessageResourceType.GetProperty(ErrorMessageResourceName);
return (string) prop.GetValue(null, BindingFlags.Static, null, null, System.Globalization.CultureInfo.CurrentUICulture);
2017-10-04 23:53:47 +02:00
}
}
}