Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DataTypeAttribute.cs
Go to the documentation of this file.
2
3[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
5{
6 private static readonly string[] _dataTypeStrings = Enum.GetNames(typeof(DataType));
7
8 public DataType DataType { get; }
9
10 public string? CustomDataType { get; }
11
12 public DisplayFormatAttribute? DisplayFormat { get; protected set; }
13
14 public DataTypeAttribute(DataType dataType)
15 {
16 DataType = dataType;
17 switch (dataType)
18 {
19 case DataType.Date:
21 DisplayFormat.DataFormatString = "{0:d}";
22 DisplayFormat.ApplyFormatInEditMode = true;
23 break;
24 case DataType.Time:
26 DisplayFormat.DataFormatString = "{0:t}";
27 DisplayFormat.ApplyFormatInEditMode = true;
28 break;
29 case DataType.Currency:
31 DisplayFormat.DataFormatString = "{0:C}";
32 break;
33 case DataType.Duration:
34 case DataType.PhoneNumber:
35 break;
36 }
37 }
38
39 public DataTypeAttribute(string customDataType)
40 : this(DataType.Custom)
41 {
42 CustomDataType = customDataType;
43 }
44
45 public virtual string GetDataTypeName()
46 {
48 if (DataType == DataType.Custom)
49 {
50 return CustomDataType;
51 }
52 return _dataTypeStrings[(int)DataType];
53 }
54
55 public override bool IsValid(object? value)
56 {
58 return true;
59 }
60
61 private void EnsureValidDataType()
62 {
63 if (DataType == DataType.Custom && string.IsNullOrWhiteSpace(CustomDataType))
64 {
66 }
67 }
68}
static string[] GetNames(Type enumType)
Definition Enum.cs:295
static string DataTypeAttribute_EmptyDataTypeString
Definition SR.cs:44
Definition SR.cs:7