BadScript 2
Loading...
Searching...
No Matches
LocalizableAttributeProperty.cs
Go to the documentation of this file.
1
using
System;
2
using
System.Reflection;
3
4
namespace
CommandLine.Infrastructure
5
{
6
internal
class
LocalizableAttributeProperty
7
{
8
private
readonly
string
_propertyName
;
9
private
PropertyInfo
_localizationPropertyInfo
;
10
private
Type
_type
;
11
private
string
_value
;
12
13
public
LocalizableAttributeProperty
(
string
propertyName)
14
{
15
_propertyName
= propertyName;
16
}
17
18
public
string
Value
19
{
20
get
=>
GetLocalizedValue
();
21
set
22
{
23
_localizationPropertyInfo
=
null
;
24
_value
= value;
25
}
26
}
27
28
public
Type
ResourceType
29
{
30
set
31
{
32
_localizationPropertyInfo
=
null
;
33
_type
= value;
34
}
35
}
36
37
private
string
GetLocalizedValue
()
38
{
39
if
(
string
.IsNullOrEmpty(
_value
) ||
_type
==
null
)
40
{
41
return
_value
;
42
}
43
44
if
(
_localizationPropertyInfo
==
null
)
45
{
46
// Static class IsAbstract
47
if
(!
_type
.IsVisible)
48
{
49
throw
new
50
ArgumentException($
"Invalid resource type '{_type.FullName}'! {_type.Name} is not visible for the parser! Change resources 'Access Modifier' to 'Public'"
,
51
_propertyName
52
);
53
}
54
55
PropertyInfo propertyInfo =
56
_type
.GetProperty(
_value
, BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.Static);
57
58
if
(propertyInfo ==
null
||
59
!propertyInfo.CanRead ||
60
(propertyInfo.PropertyType != typeof(
string
) && !propertyInfo.PropertyType.CanCast<
string
>()))
61
{
62
throw
new
ArgumentException($
"Invalid resource property name! Localized value: {_value}"
,
63
_propertyName
64
);
65
}
66
67
_localizationPropertyInfo
= propertyInfo;
68
}
69
70
return
_localizationPropertyInfo
.GetValue(
null
,
null
)
71
.Cast<
string
>();
72
}
73
}
74
}
CommandLine.Infrastructure.LocalizableAttributeProperty
Definition
LocalizableAttributeProperty.cs:7
CommandLine.Infrastructure.LocalizableAttributeProperty._value
string _value
Definition
LocalizableAttributeProperty.cs:11
CommandLine.Infrastructure.LocalizableAttributeProperty._propertyName
readonly string _propertyName
Definition
LocalizableAttributeProperty.cs:8
CommandLine.Infrastructure.LocalizableAttributeProperty._localizationPropertyInfo
PropertyInfo _localizationPropertyInfo
Definition
LocalizableAttributeProperty.cs:9
CommandLine.Infrastructure.LocalizableAttributeProperty._type
Type _type
Definition
LocalizableAttributeProperty.cs:10
CommandLine.Infrastructure.LocalizableAttributeProperty.GetLocalizedValue
string GetLocalizedValue()
Definition
LocalizableAttributeProperty.cs:37
CommandLine.Infrastructure.LocalizableAttributeProperty.Value
string Value
Definition
LocalizableAttributeProperty.cs:19
CommandLine.Infrastructure.LocalizableAttributeProperty.LocalizableAttributeProperty
LocalizableAttributeProperty(string propertyName)
Definition
LocalizableAttributeProperty.cs:13
CommandLine.Infrastructure.LocalizableAttributeProperty.ResourceType
Type ResourceType
Definition
LocalizableAttributeProperty.cs:29
CommandLine.Infrastructure
Definition
EnumerableExtensions.cs:8
deps
commandlineparser
src
CommandLine
Infrastructure
LocalizableAttributeProperty.cs
Generated by
1.9.8