Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
RegularExpressionAttribute.cs
Go to the documentation of this file.
3
5
6[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
8{
9 public int MatchTimeoutInMilliseconds { get; set; }
10
11 public string Pattern { get; }
12
13 private Regex? Regex { get; set; }
14
16 : base(() => System.SR.RegexAttribute_ValidationError)
17 {
20 }
21
22 public override bool IsValid(object? value)
23 {
24 SetupRegex();
26 if (string.IsNullOrEmpty(text))
27 {
28 return true;
29 }
31 if (match.Success && match.Index == 0)
32 {
33 return match.Length == text.Length;
34 }
35 return false;
36 }
37
38 public override string FormatErrorMessage(string name)
39 {
40 SetupRegex();
41 return string.Format(CultureInfo.CurrentCulture, base.ErrorMessageString, name, Pattern);
42 }
43
44 private void SetupRegex()
45 {
46 if (Regex == null)
47 {
48 if (string.IsNullOrEmpty(Pattern))
49 {
51 }
53 }
54 }
55}
static ? string ToString(object? value)
Definition Convert.cs:2321
static CultureInfo CurrentCulture
static string RegularExpressionAttribute_Empty_Pattern
Definition SR.cs:84
Definition SR.cs:7
static Match Match(string input, string pattern)
Definition Regex.cs:439
static TimeSpan FromMilliseconds(double value)
Definition TimeSpan.cs:228