Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
LocalizableString.cs
Go to the documentation of this file.
1
using
System.Diagnostics.CodeAnalysis
;
2
using
System.Reflection
;
3
4
namespace
System.ComponentModel.DataAnnotations
;
5
6
internal
sealed
class
LocalizableString
7
{
8
private
readonly
string
_propertyName
;
9
10
private
Func<string>
_cachedResult
;
11
12
private
string
_propertyValue
;
13
14
[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes
.PublicProperties)]
15
private
Type
_resourceType
;
16
17
public
string
Value
18
{
19
get
20
{
21
return
_propertyValue
;
22
}
23
set
24
{
25
if
(
_propertyValue
!=
value
)
26
{
27
ClearCache
();
28
_propertyValue
=
value
;
29
}
30
}
31
}
32
33
[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes
.PublicProperties)]
34
public
Type
ResourceType
35
{
36
get
37
{
38
return
_resourceType
;
39
}
40
set
41
{
42
if
(
_resourceType
!=
value
)
43
{
44
ClearCache
();
45
_resourceType
=
value
;
46
}
47
}
48
}
49
50
public
LocalizableString
(
string
propertyName)
51
{
52
_propertyName
= propertyName;
53
}
54
55
private
void
ClearCache
()
56
{
57
_cachedResult
=
null
;
58
}
59
60
public
string
GetLocalizableValue
()
61
{
62
if
(
_cachedResult
==
null
)
63
{
64
if
(
_propertyValue
==
null
||
_resourceType
==
null
)
65
{
66
_cachedResult
= () =>
_propertyValue
;
67
}
68
else
69
{
70
PropertyInfo
property
=
_resourceType
.GetRuntimeProperty(
_propertyValue
);
71
bool
flag =
false
;
72
if
(!
_resourceType
.
IsVisible
|| property ==
null
|| property.PropertyType != typeof(
string
))
73
{
74
flag =
true
;
75
}
76
else
77
{
78
MethodInfo
getMethod =
property
.GetMethod;
79
if
(getMethod ==
null
|| !getMethod.
IsPublic
|| !getMethod.
IsStatic
)
80
{
81
flag =
true
;
82
}
83
}
84
if
(flag)
85
{
86
string
exceptionMessage =
System
.
SR
.
Format
(
System
.
SR
.
LocalizableString_LocalizationFailed
,
_propertyName
,
_resourceType
.
FullName
,
_propertyValue
);
87
_cachedResult
= delegate
88
{
89
throw
new
InvalidOperationException
(exceptionMessage);
90
};
91
}
92
else
93
{
94
_cachedResult
= () => (
string
)
property
.GetValue(
null
,
null
);
95
}
96
}
97
}
98
return
_cachedResult
();
99
}
100
}
System.ComponentModel.DataAnnotations.LocalizableString._propertyValue
string _propertyValue
Definition
LocalizableString.cs:12
System.ComponentModel.DataAnnotations.LocalizableString.LocalizableString
LocalizableString(string propertyName)
Definition
LocalizableString.cs:50
System.ComponentModel.DataAnnotations.LocalizableString.Value
string Value
Definition
LocalizableString.cs:18
System.ComponentModel.DataAnnotations.LocalizableString.ClearCache
void ClearCache()
Definition
LocalizableString.cs:55
System.ComponentModel.DataAnnotations.LocalizableString._resourceType
Type _resourceType
Definition
LocalizableString.cs:15
System.ComponentModel.DataAnnotations.LocalizableString._propertyName
readonly string _propertyName
Definition
LocalizableString.cs:8
System.ComponentModel.DataAnnotations.LocalizableString.ResourceType
Type ResourceType
Definition
LocalizableString.cs:35
System.ComponentModel.DataAnnotations.LocalizableString.GetLocalizableValue
string GetLocalizableValue()
Definition
LocalizableString.cs:60
System.ComponentModel.DataAnnotations.LocalizableString._cachedResult
Func< string > _cachedResult
Definition
LocalizableString.cs:10
System.ComponentModel.DataAnnotations.LocalizableString
Definition
LocalizableString.cs:7
System.InvalidOperationException
Definition
InvalidOperationException.cs:9
System.Reflection.MethodBase.IsStatic
bool IsStatic
Definition
MethodBase.cs:50
System.Reflection.MethodBase.IsPublic
bool IsPublic
Definition
MethodBase.cs:64
System.Reflection.MethodInfo
Definition
MethodInfo.cs:7
System.Reflection.PropertyInfo
Definition
PropertyInfo.cs:8
System.SR.Format
static string Format(string resourceFormat, object p1)
Definition
SR.cs:118
System.SR.LocalizableString_LocalizationFailed
static string LocalizableString_LocalizationFailed
Definition
SR.cs:56
System.SR
Definition
SR.cs:7
System.Type.IsVisible
bool IsVisible
Definition
Type.cs:364
System.Type.FullName
string? FullName
Definition
Type.cs:47
System.Type
Definition
Type.cs:14
System.ComponentModel.DataAnnotations
Definition
ColumnAttribute.cs:3
System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes
DynamicallyAccessedMemberTypes
Definition
DynamicallyAccessedMemberTypes.cs:5
System.Diagnostics.CodeAnalysis
Definition
AllowNullAttribute.cs:1
System.Reflection
Definition
ICustomTypeProvider.cs:1
System.ExceptionArgument.value
@ value
System
Definition
BlockingCollection.cs:8
source
System.ComponentModel.Annotations
System.ComponentModel.DataAnnotations
LocalizableString.cs
Generated by
1.10.0