Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MemberDescriptor.cs
Go to the documentation of this file.
5
7
8public abstract class MemberDescriptor
9{
10 private readonly string _name;
11
12 private readonly string _displayName;
13
14 private readonly int _nameHash;
15
17
19
21
22 private bool _attributesFiltered;
23
24 private bool _attributesFilled;
25
26 private int _metadataVersion;
27
28 private string _category;
29
30 private string _description;
31
32 private readonly object _lockCookie = new object();
33
34 protected virtual Attribute[]? AttributeArray
35 {
36 get
37 {
40 return _attributes;
41 }
42 set
43 {
45 {
48 _attributesFiltered = false;
50 }
51 }
52 }
53
70
72
74
75 public virtual bool IsBrowsable => ((BrowsableAttribute)Attributes[typeof(BrowsableAttribute)]).Browsable;
76
77 public virtual string Name => _name ?? "";
78
79 protected virtual int NameHashCode => _nameHash;
80
82
83 public virtual string DisplayName
84 {
85 get
86 {
88 {
89 return _displayName;
90 }
91 return displayNameAttribute.DisplayName;
92 }
93 }
94
95 protected MemberDescriptor(string name)
96 : this(name, null)
97 {
98 }
99
100 protected MemberDescriptor(string name, Attribute[]? attributes)
101 {
102 if (name == null)
103 {
104 throw new ArgumentNullException("name");
105 }
106 if (name.Length == 0)
107 {
108 throw new ArgumentException(System.SR.InvalidMemberName, "name");
109 }
110 _name = name;
111 _displayName = name;
112 _nameHash = name.GetHashCode();
113 if (attributes != null)
114 {
115 _attributes = attributes;
116 _attributesFiltered = false;
117 }
119 }
120
122 {
123 if (descr == null)
124 {
125 throw new ArgumentNullException("descr");
126 }
127 _name = descr.Name;
129 _nameHash = _name?.GetHashCode() ?? 0;
130 _attributes = new Attribute[descr.Attributes.Count];
131 descr.Attributes.CopyTo(_attributes, 0);
132 _attributesFiltered = true;
134 }
135
137 {
138 if (oldMemberDescriptor == null)
139 {
140 throw new ArgumentNullException("oldMemberDescriptor");
141 }
143 _displayName = oldMemberDescriptor.DisplayName;
144 _nameHash = _name.GetHashCode();
146 if (oldMemberDescriptor.Attributes.Count != 0)
147 {
148 foreach (Attribute attribute in oldMemberDescriptor.Attributes)
149 {
150 list.Add(attribute);
151 }
152 }
153 if (newAttributes != null)
154 {
155 foreach (Attribute item2 in newAttributes)
156 {
157 list.Add(item2);
158 }
159 }
160 _attributes = new Attribute[list.Count];
161 list.CopyTo(_attributes, 0);
162 _attributesFiltered = false;
164 }
165
166 private void CheckAttributesValid()
167 {
169 {
170 _attributesFilled = false;
171 _attributesFiltered = false;
173 }
174 }
175
177 {
179 }
180
181 public override bool Equals([NotNullWhen(true)] object? obj)
182 {
183 if (this == obj)
184 {
185 return true;
186 }
187 if (obj == null)
188 {
189 return false;
190 }
191 if (obj.GetType() != GetType())
192 {
193 return false;
194 }
197 memberDescriptor.FilterAttributesIfNeeded();
198 if (memberDescriptor._nameHash != _nameHash)
199 {
200 return false;
201 }
202 if (memberDescriptor._category == null != (_category == null) || (_category != null && !memberDescriptor._category.Equals(_category)))
203 {
204 return false;
205 }
206 if (memberDescriptor._description == null != (_description == null) || (_description != null && !memberDescriptor._description.Equals(_description)))
207 {
208 return false;
209 }
210 if (memberDescriptor._attributes == null != (_attributes == null))
211 {
212 return false;
213 }
214 bool result = true;
215 if (_attributes != null)
216 {
217 if (_attributes.Length != memberDescriptor._attributes.Length)
218 {
219 return false;
220 }
221 for (int i = 0; i < _attributes.Length; i++)
222 {
223 if (!_attributes[i].Equals(memberDescriptor._attributes[i]))
224 {
225 result = false;
226 break;
227 }
228 }
229 }
230 return result;
231 }
232
233 protected virtual void FillAttributes(IList attributeList)
234 {
235 if (attributeList == null)
236 {
237 throw new ArgumentNullException("attributeList");
238 }
239 if (_originalAttributes != null)
240 {
243 {
245 }
246 }
247 }
248
250 {
252 {
253 return;
254 }
257 {
258 list = new List<Attribute>();
259 try
260 {
262 }
263 catch (Exception)
264 {
265 }
266 }
267 else
268 {
270 }
272 int num = 0;
273 while (num < list.Count)
274 {
275 int value = -1;
276 object obj = list[num]?.TypeId;
277 if (obj == null)
278 {
279 list.RemoveAt(num);
280 }
281 else if (!dictionary.TryGetValue(obj, out value))
282 {
283 dictionary.Add(obj, num);
284 num++;
285 }
286 else
287 {
288 list[value] = list[num];
289 list.RemoveAt(num);
290 }
291 }
292 Attribute[] attributes = list.ToArray();
294 {
295 _attributes = attributes;
296 _attributesFiltered = true;
297 _attributesFilled = true;
299 }
300 }
301
302 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2067:UnrecognizedReflectionPattern", Justification = "This method only looks for public methods by hard-coding publicOnly=true")]
307
309 {
310 if (componentClass == null)
311 {
312 throw new ArgumentNullException("componentClass");
313 }
314 MethodInfo methodInfo = null;
315 methodInfo = ((!publicOnly) ? componentClass.GetMethod(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, args, null) : componentClass.GetMethod(name, args));
316 if (methodInfo != null && !methodInfo.ReturnType.IsEquivalentTo(returnType))
317 {
318 methodInfo = null;
319 }
320 return methodInfo;
321 }
322
323 public override int GetHashCode()
324 {
325 return _nameHash;
326 }
327
328 protected virtual object? GetInvocationTarget(Type type, object instance)
329 {
330 if (type == null)
331 {
332 throw new ArgumentNullException("type");
333 }
334 if (instance == null)
335 {
336 throw new ArgumentNullException("instance");
337 }
338 return TypeDescriptor.GetAssociation(type, instance);
339 }
340
341 protected static ISite? GetSite(object? component)
342 {
343 return (component as IComponent)?.Site;
344 }
345
346 [Obsolete("MemberDescriptor.GetInvokee has been deprecated. Use GetInvocationTarget instead.")]
347 protected static object GetInvokee(Type componentClass, object component)
348 {
349 if (componentClass == null)
350 {
351 throw new ArgumentNullException("componentClass");
352 }
353 if (component == null)
354 {
355 throw new ArgumentNullException("component");
356 }
358 }
359}
void CopyTo(KeyValuePair< TKey, TValue >[] array, int index)
void Add(TKey key, TValue value)
static readonly DesignOnlyAttribute Yes
static ? ISite GetSite(object? component)
static ? MethodInfo FindMethod([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods|DynamicallyAccessedMemberTypes.NonPublicMethods)] Type componentClass, string name, Type[] args, Type returnType, bool publicOnly)
override bool Equals([NotNullWhen(true)] object? obj)
static object GetInvokee(Type componentClass, object component)
virtual ? object GetInvocationTarget(Type type, object instance)
static ? MethodInfo FindMethod([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type componentClass, string name, Type[] args, Type returnType)
MemberDescriptor(MemberDescriptor oldMemberDescriptor, Attribute[]? newAttributes)
MemberDescriptor(string name, Attribute[]? attributes)
virtual AttributeCollection CreateAttributeCollection()
virtual void FillAttributes(IList attributeList)
virtual AttributeCollection Attributes
static object GetAssociation(Type type, object primary)
static string InvalidMemberName
Definition SR.cs:36
Definition SR.cs:7