Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DataTypeAttribute.cs
Go to the documentation of this file.
1
namespace
System.ComponentModel.DataAnnotations
;
2
3
[AttributeUsage(
AttributeTargets
.Method |
AttributeTargets
.Property |
AttributeTargets
.Field |
AttributeTargets
.Parameter, AllowMultiple =
false
)]
4
public
class
DataTypeAttribute
:
ValidationAttribute
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:
20
DisplayFormat
=
new
DisplayFormatAttribute
();
21
DisplayFormat.DataFormatString =
"{0:d}"
;
22
DisplayFormat.ApplyFormatInEditMode =
true
;
23
break
;
24
case
DataType
.Time:
25
DisplayFormat
=
new
DisplayFormatAttribute
();
26
DisplayFormat.DataFormatString =
"{0:t}"
;
27
DisplayFormat.ApplyFormatInEditMode =
true
;
28
break
;
29
case
DataType
.Currency:
30
DisplayFormat
=
new
DisplayFormatAttribute
();
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
{
47
EnsureValidDataType
();
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
{
57
EnsureValidDataType
();
58
return
true
;
59
}
60
61
private
void
EnsureValidDataType
()
62
{
63
if
(
DataType
==
DataType
.Custom &&
string
.IsNullOrWhiteSpace(
CustomDataType
))
64
{
65
throw
new
InvalidOperationException
(
System
.
SR
.
DataTypeAttribute_EmptyDataTypeString
);
66
}
67
}
68
}
System.ComponentModel.DataAnnotations.DataTypeAttribute.DataTypeAttribute
DataTypeAttribute(DataType dataType)
Definition
DataTypeAttribute.cs:14
System.ComponentModel.DataAnnotations.DataTypeAttribute.DisplayFormat
DisplayFormatAttribute? DisplayFormat
Definition
DataTypeAttribute.cs:12
System.ComponentModel.DataAnnotations.DataTypeAttribute.GetDataTypeName
virtual string GetDataTypeName()
Definition
DataTypeAttribute.cs:45
System.ComponentModel.DataAnnotations.DataTypeAttribute.EnsureValidDataType
void EnsureValidDataType()
Definition
DataTypeAttribute.cs:61
System.ComponentModel.DataAnnotations.DataTypeAttribute.CustomDataType
string? CustomDataType
Definition
DataTypeAttribute.cs:10
System.ComponentModel.DataAnnotations.DataTypeAttribute._dataTypeStrings
static readonly string[] _dataTypeStrings
Definition
DataTypeAttribute.cs:6
System.ComponentModel.DataAnnotations.DataTypeAttribute.DataTypeAttribute
DataTypeAttribute(string customDataType)
Definition
DataTypeAttribute.cs:39
System.ComponentModel.DataAnnotations.DataTypeAttribute.IsValid
override bool IsValid(object? value)
Definition
DataTypeAttribute.cs:55
System.ComponentModel.DataAnnotations.DataTypeAttribute
Definition
DataTypeAttribute.cs:5
System.ComponentModel.DataAnnotations.DisplayFormatAttribute
Definition
DisplayFormatAttribute.cs:7
System.ComponentModel.DataAnnotations.ValidationAttribute
Definition
ValidationAttribute.cs:8
System.Enum.GetNames
static string[] GetNames(Type enumType)
Definition
Enum.cs:295
System.Enum
Definition
Enum.cs:14
System.InvalidOperationException
Definition
InvalidOperationException.cs:9
System.SR.DataTypeAttribute_EmptyDataTypeString
static string DataTypeAttribute_EmptyDataTypeString
Definition
SR.cs:44
System.SR
Definition
SR.cs:7
System.ComponentModel.DataAnnotations.DataType
DataType
Definition
DataType.cs:4
System.ComponentModel.DataAnnotations.DataType.Custom
@ Custom
System.ComponentModel.DataAnnotations
Definition
ColumnAttribute.cs:3
System.ExceptionArgument.value
@ value
System.AttributeTargets
AttributeTargets
Definition
AttributeTargets.cs:5
System
Definition
BlockingCollection.cs:8
source
System.ComponentModel.Annotations
System.ComponentModel.DataAnnotations
DataTypeAttribute.cs
Generated by
1.10.0