Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ComponentResourceManager.cs
Go to the documentation of this file.
7
9
11{
13
15
27
29 {
30 }
31
33 : base(t)
34 {
35 }
36
37 [RequiresUnreferencedCode("The Type of value cannot be statically discovered.")]
38 public void ApplyResources(object value, string objectName)
39 {
41 }
42
43 [RequiresUnreferencedCode("The Type of value cannot be statically discovered.")]
44 public virtual void ApplyResources(object value, string objectName, CultureInfo? culture)
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;
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 {
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 {
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 }
138
153}
IEqualityComparer< TKey > Comparer
bool ICollection< KeyValuePair< TKey, TValue > >. IsReadOnly
SortedList< string, object > FillResources(CultureInfo culture, out ResourceSet resourceSet)
void ApplyResources(object value, string objectName)
virtual void ApplyResources(object value, string objectName, CultureInfo? culture)
static PropertyDescriptorCollection GetProperties([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type componentType)
static CultureInfo CurrentUICulture
static CultureInfo InvariantCulture
void SetValue(object? obj, object? value)
static CultureInfo GetNeutralResourcesLanguage(Assembly a)
virtual ? ResourceSet GetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents)
static StringComparer Ordinal
static StringComparer OrdinalIgnoreCase
static ? Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Definition Type.cs:408
virtual bool IsInstanceOfType([NotNullWhen(true)] object? o)
Definition Type.cs:1020
new bool Equals(object? x, object? y)