BadScript 2
Loading...
Searching...
No Matches
CommandLine.Infrastructure.LocalizableAttributeProperty Class Reference

Public Member Functions

 LocalizableAttributeProperty (string propertyName)
 

Properties

string Value [get, set]
 
Type ResourceType [set]
 

Private Member Functions

string GetLocalizedValue ()
 

Private Attributes

readonly string _propertyName
 
PropertyInfo _localizationPropertyInfo
 
Type _type
 
string _value
 

Detailed Description

Definition at line 6 of file LocalizableAttributeProperty.cs.

Constructor & Destructor Documentation

◆ LocalizableAttributeProperty()

CommandLine.Infrastructure.LocalizableAttributeProperty.LocalizableAttributeProperty ( string  propertyName)

Definition at line 13 of file LocalizableAttributeProperty.cs.

Member Function Documentation

◆ GetLocalizedValue()

string CommandLine.Infrastructure.LocalizableAttributeProperty.GetLocalizedValue ( )
private

Definition at line 37 of file LocalizableAttributeProperty.cs.

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'",
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}",
64 );
65 }
66
67 _localizationPropertyInfo = propertyInfo;
68 }
69
70 return _localizationPropertyInfo.GetValue(null, null)
71 .Cast<string>();
72 }

Member Data Documentation

◆ _localizationPropertyInfo

PropertyInfo CommandLine.Infrastructure.LocalizableAttributeProperty._localizationPropertyInfo
private

Definition at line 9 of file LocalizableAttributeProperty.cs.

◆ _propertyName

readonly string CommandLine.Infrastructure.LocalizableAttributeProperty._propertyName
private

Definition at line 8 of file LocalizableAttributeProperty.cs.

◆ _type

Type CommandLine.Infrastructure.LocalizableAttributeProperty._type
private

Definition at line 10 of file LocalizableAttributeProperty.cs.

◆ _value

string CommandLine.Infrastructure.LocalizableAttributeProperty._value
private

Definition at line 11 of file LocalizableAttributeProperty.cs.

Property Documentation

◆ ResourceType

Type CommandLine.Infrastructure.LocalizableAttributeProperty.ResourceType
set

Definition at line 28 of file LocalizableAttributeProperty.cs.

29 {
30 set
31 {
33 _type = value;
34 }
35 }

◆ Value

string CommandLine.Infrastructure.LocalizableAttributeProperty.Value
getset

Definition at line 18 of file LocalizableAttributeProperty.cs.

19 {
20 get => GetLocalizedValue();
21 set
22 {
24 _value = value;
25 }
26 }

The documentation for this class was generated from the following file: