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

◆ GetCustomAttributes() [10/10]

static object[] System.Reflection.CustomAttribute.GetCustomAttributes ( RuntimeType type,
RuntimeType caType,
bool inherit )
inlinestaticpackage

Definition at line 112 of file CustomAttribute.cs.

113 {
114 if ((object)type.GetElementType() != null)
115 {
116 if (!caType.IsValueType)
117 {
118 return CreateAttributeArrayHelper(caType, 0);
119 }
120 return Array.Empty<object>();
121 }
122 if (type.IsGenericType && !type.IsGenericTypeDefinition)
123 {
124 type = type.GetGenericTypeDefinition() as RuntimeType;
125 }
126 RuntimeType.ListBuilder<Attribute> pcas = default(RuntimeType.ListBuilder<Attribute>);
127 PseudoCustomAttribute.GetCustomAttributes(type, caType, ref pcas);
128 if (!inherit || (caType.IsSealed && !GetAttributeUsage(caType).Inherited))
129 {
130 object[] customAttributes = GetCustomAttributes(type.GetRuntimeModule(), type.MetadataToken, pcas.Count, caType);
131 if (pcas.Count > 0)
132 {
133 pcas.CopyTo(customAttributes, customAttributes.Length - pcas.Count);
134 }
135 return customAttributes;
136 }
137 RuntimeType.ListBuilder<object> attributes = default(RuntimeType.ListBuilder<object>);
138 bool mustBeInheritable = false;
139 RuntimeType elementType = ((caType.IsValueType || caType.ContainsGenericParameters) ? ((RuntimeType)typeof(object)) : caType);
140 for (int i = 0; i < pcas.Count; i++)
141 {
142 attributes.Add(pcas[i]);
143 }
144 while (type != (RuntimeType)typeof(object) && type != null)
145 {
146 AddCustomAttributes(ref attributes, type.GetRuntimeModule(), type.MetadataToken, caType, mustBeInheritable, attributes);
147 mustBeInheritable = true;
148 type = type.BaseType as RuntimeType;
149 }
150 object[] array = CreateAttributeArrayHelper(elementType, attributes.Count);
151 for (int j = 0; j < attributes.Count; j++)
152 {
153 array[j] = attributes[j];
154 }
155 return array;
156 }
static object[] GetCustomAttributes(RuntimeType type, RuntimeType caType, bool inherit)
static object[] CreateAttributeArrayHelper(RuntimeType elementType, int elementCount)
static unsafe void AddCustomAttributes(ref RuntimeType.ListBuilder< object > attributes, RuntimeModule decoratedModule, int decoratedMetadataToken, RuntimeType attributeFilterType, bool mustBeInheritable, RuntimeType.ListBuilder< object > derivedAttributes)
static AttributeUsageAttribute GetAttributeUsage(RuntimeType decoratedAttribute)

References System.Reflection.CustomAttribute.AddCustomAttributes(), System.array, System.RuntimeType.ContainsGenericParameters, System.Reflection.CustomAttribute.CreateAttributeArrayHelper(), System.elementType, System.Reflection.CustomAttribute.GetAttributeUsage(), System.Reflection.CustomAttribute.GetCustomAttributes(), System.Reflection.PseudoCustomAttribute.GetCustomAttributes(), System.Type.IsSealed, System.Type.IsValueType, and System.type.

Referenced by System.Reflection.Emit.TypeBuilder.GetCustomAttributes(), System.Reflection.RuntimeAssembly.GetCustomAttributes(), System.Reflection.RuntimeConstructorInfo.GetCustomAttributes(), System.Reflection.RuntimeEventInfo.GetCustomAttributes(), System.Reflection.RuntimeFieldInfo.GetCustomAttributes(), System.Reflection.RuntimeMethodInfo.GetCustomAttributes(), System.Reflection.RuntimeModule.GetCustomAttributes(), System.Reflection.RuntimeParameterInfo.GetCustomAttributes(), System.Reflection.RuntimePropertyInfo.GetCustomAttributes(), System.RuntimeType.GetCustomAttributes(), System.Reflection.CustomAttribute.GetCustomAttributes(), System.Reflection.CustomAttribute.GetCustomAttributes(), System.Reflection.CustomAttribute.GetCustomAttributes(), System.Reflection.CustomAttribute.GetCustomAttributes(), System.Reflection.CustomAttribute.GetCustomAttributes(), System.Reflection.CustomAttribute.GetCustomAttributes(), System.Reflection.CustomAttribute.GetCustomAttributes(), System.Reflection.CustomAttribute.GetCustomAttributes(), System.Reflection.CustomAttribute.GetCustomAttributes(), System.Reflection.Emit.TypeBuilder.GetCustomAttributes(), System.Reflection.RuntimeAssembly.GetCustomAttributes(), System.Reflection.RuntimeConstructorInfo.GetCustomAttributes(), System.Reflection.RuntimeEventInfo.GetCustomAttributes(), System.Reflection.RuntimeFieldInfo.GetCustomAttributes(), System.Reflection.RuntimeMethodInfo.GetCustomAttributes(), System.Reflection.RuntimeModule.GetCustomAttributes(), System.Reflection.RuntimeParameterInfo.GetCustomAttributes(), System.Reflection.RuntimePropertyInfo.GetCustomAttributes(), and System.RuntimeType.GetCustomAttributes().