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

◆ GetDefaultAttribute()

Attribute? System.ComponentModel.AttributeCollection.GetDefaultAttribute ( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.PublicFields)] Type attributeType)
inlineprotected

Definition at line 194 of file AttributeCollection.cs.

195 {
196 if (attributeType == null)
197 {
198 throw new ArgumentNullException("attributeType");
199 }
201 {
202 if (s_defaultAttributes == null)
203 {
205 }
206 if (s_defaultAttributes.ContainsKey(attributeType))
207 {
208 return (Attribute)s_defaultAttributes[attributeType];
209 }
210 Attribute attribute = null;
211 Type reflectionType = TypeDescriptor.GetReflectionType(attributeType);
212 FieldInfo field = reflectionType.GetField("Default", BindingFlags.Static | BindingFlags.Public | BindingFlags.GetField);
213 if (field != null && field.IsStatic)
214 {
215 attribute = (Attribute)field.GetValue(null);
216 }
217 else
218 {
219 ConstructorInfo constructor = reflectionType.UnderlyingSystemType.GetConstructor(Type.EmptyTypes);
220 if (constructor != null)
221 {
222 attribute = (Attribute)constructor.Invoke(Array.Empty<object>());
223 if (!attribute.IsDefaultAttribute())
224 {
225 attribute = null;
226 }
227 }
228 }
230 return attribute;
231 }
232 }
virtual ? Attribute this[[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor|DynamicallyAccessedMemberTypes.PublicFields)] Type attributeType
object Invoke(object?[]? parameters)
object? GetValue(object? obj)

References System.ComponentModel.AttributeCollection.attributeType, System.Type.EmptyTypes, System.Type.GetConstructor(), System.Type.GetField(), System.ComponentModel.TypeDescriptor.GetReflectionType(), System.Reflection.FieldInfo.GetValue(), System.Reflection.ConstructorInfo.Invoke(), System.Attribute.IsDefaultAttribute(), System.Reflection.FieldInfo.IsStatic, System.ComponentModel.AttributeCollection.s_defaultAttributes, System.ComponentModel.AttributeCollection.s_internalSyncObject, and System.Type.UnderlyingSystemType.