Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ApplyResources() [2/2]

virtual void System.ComponentModel.ComponentResourceManager.ApplyResources ( object value,
string objectName,
CultureInfo? culture )
inlinevirtual

Definition at line 44 of file ComponentResourceManager.cs.

45 {
46 if (value == null)
47 {
48 throw new ArgumentNullException("value");
49 }
50 if (objectName == null)
51 {
52 throw new ArgumentNullException("objectName");
53 }
54 if (culture == null)
55 {
57 }
59 if (_resourceSets == null)
60 {
62 sortedList = FillResources(culture, out var _);
63 _resourceSets[culture] = sortedList;
64 }
65 else
66 {
68 if (sortedList == null || sortedList.Comparer.Equals(StringComparer.OrdinalIgnoreCase) != IgnoreCase)
69 {
70 sortedList = FillResources(culture, out var _);
71 _resourceSets[culture] = sortedList;
72 }
73 }
74 BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty;
75 if (IgnoreCase)
76 {
77 bindingFlags |= BindingFlags.IgnoreCase;
78 }
79 bool flag = false;
80 if (value is IComponent)
81 {
82 ISite site = ((IComponent)value).Site;
83 if (site != null && site.DesignMode)
84 {
85 flag = true;
86 }
87 }
88 foreach (KeyValuePair<string, object> item in sortedList)
89 {
90 string key = item.Key;
91 if (IgnoreCase)
92 {
93 if (string.Compare(key, 0, objectName, 0, objectName.Length, StringComparison.OrdinalIgnoreCase) != 0)
94 {
95 continue;
96 }
97 }
98 else if (string.CompareOrdinal(key, 0, objectName, 0, objectName.Length) != 0)
99 {
100 continue;
101 }
102 int length = objectName.Length;
103 if (key.Length <= length || (key[length] != '.' && key[length] != '-'))
104 {
105 continue;
106 }
107 string name = key.Substring(length + 1);
108 if (flag)
109 {
110 PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(value).Find(name, IgnoreCase);
111 if (propertyDescriptor != null && !propertyDescriptor.IsReadOnly && (item.Value == null || propertyDescriptor.PropertyType.IsInstanceOfType(item.Value)))
112 {
113 propertyDescriptor.SetValue(value, item.Value);
114 }
115 continue;
116 }
117 PropertyInfo propertyInfo = null;
118 try
119 {
120 propertyInfo = value.GetType().GetProperty(name, bindingFlags);
121 }
123 {
124 Type type = value.GetType();
125 do
126 {
127 propertyInfo = type.GetProperty(name, bindingFlags | BindingFlags.DeclaredOnly);
128 type = type.BaseType;
129 }
130 while (propertyInfo == null && type != null && type != typeof(object));
131 }
132 if (propertyInfo != null && propertyInfo.CanWrite && (item.Value == null || propertyInfo.PropertyType.IsInstanceOfType(item.Value)))
133 {
134 propertyInfo.SetValue(value, item.Value, null);
135 }
136 }
137 }
IEqualityComparer< TKey > Comparer
bool ICollection< KeyValuePair< TKey, TValue > >. IsReadOnly
SortedList< string, object > FillResources(CultureInfo culture, out ResourceSet resourceSet)
static CultureInfo CurrentUICulture
void SetValue(object? obj, object? value)
virtual bool IsInstanceOfType([NotNullWhen(true)] object? o)
Definition Type.cs:1020
new bool Equals(object? x, object? y)

References System.ComponentModel.ComponentResourceManager._resourceSets, System.Reflection.PropertyInfo.CanWrite, System.Collections.Generic.Dictionary< TKey, TValue >.Comparer, System.culture, System.Globalization.CultureInfo.CurrentUICulture, System.Collections.IEqualityComparer.Equals(), System.ComponentModel.ComponentResourceManager.FillResources(), System.ComponentModel.TypeDescriptor.GetProperties(), System.Type.GetType(), System.Resources.ResourceManager.IgnoreCase, System.Type.IsInstanceOfType(), System.Collections.Generic.Dictionary< TKey, TValue >.IsReadOnly, System.item, System.key, System.length, System.StringComparer.OrdinalIgnoreCase, System.Reflection.PropertyInfo.PropertyType, System.Reflection.PropertyInfo.SetValue(), System.type, and System.value.