Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MaxLengthAttribute.cs
Go to the documentation of this file.
3
5
6[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
8{
9 public int Length { get; }
10
12
13 [RequiresUnreferencedCode("Uses reflection to get the 'Count' property on types that don't implement ICollection. This 'Count' property may be trimmed. Ensure it is preserved.")]
15 : base(() => DefaultErrorMessageString)
16 {
17 Length = length;
18 }
19
20 [RequiresUnreferencedCode("Uses reflection to get the 'Count' property on types that don't implement ICollection. This 'Count' property may be trimmed. Ensure it is preserved.")]
22 : base(() => DefaultErrorMessageString)
23 {
24 Length = -1;
25 }
26
27 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The ctors are marked with RequiresUnreferencedCode.")]
28 public override bool IsValid(object? value)
29 {
31 if (value == null)
32 {
33 return true;
34 }
35 int num;
36 if (value is string text)
37 {
38 num = text.Length;
39 }
40 else
41 {
43 {
45 }
46 num = count;
47 }
48 if (-1 != Length)
49 {
50 return num <= Length;
51 }
52 return true;
53 }
54
55 public override string FormatErrorMessage(string name)
56 {
57 return string.Format(CultureInfo.CurrentCulture, base.ErrorMessageString, name, Length);
58 }
59
60 private void EnsureLegalLengths()
61 {
62 if (Length == 0 || Length < -1)
63 {
65 }
66 }
67}
static bool TryGetCount(object value, out int count)
static CultureInfo CurrentCulture
static string MaxLengthAttribute_InvalidMaxLength
Definition SR.cs:58
static string MaxLengthAttribute_ValidationError
Definition SR.cs:60
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string LengthAttribute_InvalidValueType
Definition SR.cs:68
Definition SR.cs:7