15 if ((
object)
type.GetElementType() !=
null)
32 while ((
object)
type !=
null)
58 while ((
object)method !=
null)
114 if ((
object)
type.GetElementType() !=
null)
120 return Array.Empty<
object>();
122 if (
type.IsGenericType && !
type.IsGenericTypeDefinition)
133 pcas.CopyTo(customAttributes, customAttributes.Length - pcas.Count);
135 return customAttributes;
138 bool mustBeInheritable =
false;
140 for (
int i = 0; i < pcas.Count; i++)
142 attributes.Add(pcas[i]);
147 mustBeInheritable =
true;
151 for (
int j = 0; j < attributes.Count; j++)
153 array[j] = attributes[j];
171 pcas.CopyTo(customAttributes, customAttributes.Length - pcas.Count);
173 return customAttributes;
176 bool mustBeInheritable =
false;
178 for (
int i = 0; i < pcas.Count; i++)
180 attributes.Add(pcas[i]);
182 while (method !=
null)
185 mustBeInheritable =
true;
189 for (
int j = 0; j < attributes.Count; j++)
191 array[j] = attributes[j];
218 pcas.CopyTo(customAttributes, customAttributes.Length - pcas.Count);
220 return customAttributes;
230 pcas.CopyTo(customAttributes, customAttributes.Length - pcas.Count);
232 return customAttributes;
248 return IsCustomAttributeDefined(decoratedModule, decoratedMetadataToken, attributeFilterType, 0, mustBeInheritable:
false);
255 if (result.Length == 0)
260 if ((
object)attributeFilterType !=
null)
263 for (
int i = 0; i < result.Length; i++)
266 if (
FilterCustomAttributeRecord(customAttributeRecord.
tkCtor, in scope, decoratedModule, decoratedMetadataToken, attributeFilterType, mustBeInheritable, ref derivedAttributes, out var _, out var _, out var _))
274 for (
int j = 0; j < result.Length; j++)
277 if ((
int)customAttributeRecord.
tkCtor == attributeCtorToken)
292 for (
int i = 0; i < attributes.Count; i++)
294 array[i] = attributes[i];
299 [UnconditionalSuppressMessage(
"ReflectionAnalysis",
"IL2065:UnrecognizedReflectionPattern", Justification =
"Linker guarantees presence of all the constructor parameters, property setters and fields which are accessed by any attribute instantiation which is present in the code linker has analyzed.As such the reflection usage in this method will never fail as those methods/fields will be present.")]
303 if ((
object)attributeFilterType ==
null && customAttributeRecords.Length == 0)
308 for (
int i = 0; i < customAttributeRecords.Length; i++)
311 IntPtr blob = reference.blob.Signature;
312 IntPtr intPtr = (
IntPtr)((
byte*)(
void*)blob + reference.blob.Length);
313 if (!
FilterCustomAttributeRecord(reference.tkCtor, in scope, decoratedModule, decoratedMetadataToken, attributeFilterType, mustBeInheritable, ref derivedAttributes, out var attributeType, out var ctorWithParameters, out var isVarArg))
320 if (ctorWithParameters !=
null)
322 obj =
CreateCaObject(decoratedModule, attributeType, ctorWithParameters, ref blob, intPtr, out namedArgs);
326 obj = attributeType.CreateInstanceDefaultCtor(publicOnly:
false, wrapExceptions:
false);
327 if ((
int)((
byte*)(
void*)intPtr - (
byte*)(
void*)blob) == 0)
333 int num =
Unsafe.ReadUnaligned<
int>((
void*)blob);
334 if ((num & 0xFFFF) != 1)
338 namedArgs = num >> 16;
339 blob = (
IntPtr)((
byte*)(
void*)blob + 4);
342 for (
int j = 0; j < namedArgs; j++)
349 if ((
object)
type ==
null &&
value !=
null)
358 if ((
object)propertyInfo ==
null)
370 FieldInfo field = attributeType.GetField(name);
387 [UnconditionalSuppressMessage(
"ReflectionAnalysis",
"IL2026:RequiresUnreferencedCode", Justification =
"Module.ResolveMethod and Module.ResolveType are marked as RequiresUnreferencedCode because they rely on tokenswhich are not guaranteed to be stable across trimming. So if somebody hardcodes a token it could break.The usage here is not like that as all these tokens come from existing metadata loaded from some ILand so trimming has no effect (the tokens are read AFTER trimming occured).")]
390 ctorWithParameters =
null;
392 attributeType = decoratedModule.
ResolveType(scope.GetParentToken(caCtorToken),
null,
null) as
RuntimeType;
397 if (!AttributeUsageCheck(attributeType, mustBeInheritable, ref derivedAttributes))
405 ConstArray methodSignature = scope.GetMethodSignature(caCtorToken);
406 isVarArg = (methodSignature[0] & 5) != 0;
407 if (methodSignature[1] != 0)
409 if (attributeType.IsGenericType)
421 metadataToken =
new MetadataToken(scope.GetParentToken(decoratedToken));
422 metadataToken =
new MetadataToken(scope.GetParentToken(metadataToken));
426 metadataToken =
new MetadataToken(scope.GetParentToken(decoratedToken));
430 metadataToken = decoratedToken;
434 metadataToken =
new MetadataToken(scope.GetParentToken(decoratedToken));
437 metadataToken =
new MetadataToken(scope.GetParentToken(metadataToken));
450 if (mustBeInheritable)
452 attributeUsageAttribute = GetAttributeUsage(attributeType);
458 if (derivedAttributes.Count == 0)
462 for (
int i = 0; i < derivedAttributes.Count; i++)
464 if (derivedAttributes[i].GetType() == attributeType)
466 if (attributeUsageAttribute ==
null)
468 attributeUsageAttribute = GetAttributeUsage(attributeType);
476 [UnconditionalSuppressMessage(
"ReflectionAnalysis",
"IL2026:RequiresUnreferencedCode", Justification =
"Module.ResolveType is marked as RequiresUnreferencedCode because it relies on tokenswhich are not guaranteed to be stable across trimming. So if somebody hardcodes a token it could break.The usage here is not like that as all these tokens come from existing metadata loaded from some ILand so trimming has no effect (the tokens are read AFTER trimming occured).")]
483 for (
int i = 0; i < customAttributeRecords.Length; i++)
489 if (attributeUsageAttribute !=
null)
493 ParseAttributeUsageAttribute(reference.blob, out var targets, out var inherited, out var allowMultiple);
505 _ParseAttributeUsageAttribute(ca.
Signature, ca.
Length, out var targets2, out inherited, out allowMultiple);
514 byte* ptr = (
byte*)(
void*)blob;
515 byte* pEndBlob = (
byte*)(
void*)blobEnd;
517 object result = _CreateCaObject(module,
type, ctor, &ptr, pEndBlob, &num);
528 byte* ptr = (
byte*)(
void*)blobStart;
529 _GetPropertyOrFieldData(module, &ptr, (
byte*)(
void*)blobEnd, out name, out isProperty, out
type, out
value);
535 if (elementCount == 0)
static unsafe Array CreateInstance(Type elementType, int length)
static readonly AttributeUsageAttribute Default
static void KeepAlive(object? obj)
static object[] GetCustomAttributes(RuntimeModule module, RuntimeType caType)
static unsafe object CreateCaObject(RuntimeModule module, RuntimeType type, IRuntimeMethodInfo ctor, ref IntPtr blob, IntPtr blobEnd, out int namedArgs)
static object[] GetCustomAttributes(RuntimeFieldInfo field, RuntimeType caType)
static bool IsDefined(RuntimeAssembly assembly, RuntimeType caType)
static object[] GetCustomAttributes(RuntimeConstructorInfo ctor, RuntimeType caType)
static bool IsDefined(RuntimeEventInfo e, RuntimeType caType)
static unsafe object _CreateCaObject(RuntimeModule pModule, RuntimeType type, IRuntimeMethodInfo pCtor, byte **ppBlob, byte *pEndBlob, int *pcNamedArgs)
static bool IsDefined(RuntimeConstructorInfo ctor, RuntimeType caType)
static bool IsDefined(RuntimeParameterInfo parameter, RuntimeType caType)
static bool IsCustomAttributeDefined(RuntimeModule decoratedModule, int decoratedMetadataToken, RuntimeType attributeFilterType)
static void ParseAttributeUsageAttribute(ConstArray ca, out AttributeTargets targets, out bool inherited, out bool allowMultiple)
static bool IsDefined(RuntimePropertyInfo property, RuntimeType caType)
static bool AttributeUsageCheck(RuntimeType attributeType, bool mustBeInheritable, ref RuntimeType.ListBuilder< object > derivedAttributes)
static bool IsDefined(RuntimeModule module, RuntimeType caType)
static object[] GetCustomAttributes(RuntimeParameterInfo parameter, RuntimeType caType)
static unsafe void _GetPropertyOrFieldData(RuntimeModule pModule, byte **ppBlobStart, byte *pBlobEnd, out string name, out bool bIsProperty, out RuntimeType type, out object value)
static object[] GetCustomAttributes(RuntimePropertyInfo property, RuntimeType caType)
static object[] GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
static object[] GetCustomAttributes(RuntimeType type, RuntimeType caType, bool inherit)
static object[] GetCustomAttributes(RuntimeModule decoratedModule, int decoratedMetadataToken, int pcaCount, RuntimeType attributeFilterType)
static object[] CreateAttributeArrayHelper(RuntimeType elementType, int elementCount)
static bool IsDefined(RuntimeFieldInfo field, RuntimeType caType)
static bool IsCustomAttributeDefined(RuntimeModule decoratedModule, int decoratedMetadataToken, RuntimeType attributeFilterType, int attributeCtorToken, bool mustBeInheritable)
static object[] GetCustomAttributes(RuntimeEventInfo e, RuntimeType caType)
static bool IsDefined(RuntimeType type, RuntimeType caType, bool inherit)
static void _ParseAttributeUsageAttribute(IntPtr pCa, int cCa, out int targets, out bool inherited, out bool allowMultiple)
static unsafe void AddCustomAttributes(ref RuntimeType.ListBuilder< object > attributes, RuntimeModule decoratedModule, int decoratedMetadataToken, RuntimeType attributeFilterType, bool mustBeInheritable, RuntimeType.ListBuilder< object > derivedAttributes)
static bool FilterCustomAttributeRecord(MetadataToken caCtorToken, in MetadataImport scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, bool mustBeInheritable, ref RuntimeType.ListBuilder< object > derivedAttributes, out RuntimeType attributeType, out IRuntimeMethodInfo ctorWithParameters, out bool isVarArg)
static readonly RuntimeType Type_RuntimeType
static AttributeUsageAttribute GetAttributeUsage(RuntimeType decoratedAttribute)
static bool IsDefined(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
static unsafe void GetPropertyOrFieldData(RuntimeModule module, ref IntPtr blobStart, IntPtr blobEnd, out string name, out bool isProperty, out RuntimeType type, out object value)
static object[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
static readonly RuntimeType Type_Type
void SetValue(object? obj, object? value)
virtual int MetadataToken
object? Invoke(object? obj, object?[]? parameters)
RuntimeMethodHandle MethodHandle
ModuleHandle ModuleHandle
MethodInfo? GetSetMethod()
static bool IsDefined(RuntimeType type, RuntimeType caType)
static void GetCustomAttributes(RuntimeType type, RuntimeType caType, ref RuntimeType.ListBuilder< Attribute > pcas)
override Module ManifestModule
static int GetToken(RuntimeAssembly assembly)
RuntimeAssembly GetNativeHandle()
RuntimeModule GetRuntimeModule()
override int MetadataToken
static void CheckCanCreateInstance(Type declaringType, bool isVarArg)
static CustomAttributeRecord[] GetCustomAttributeRecords(RuntimeModule module, int targetToken)
override int MetadataToken
RuntimeModule GetRuntimeModule()
RuntimeModule GetRuntimeModule()
override bool IsGenericMethodDefinition
RuntimeModule GetRuntimeModule()
override int MetadataToken
RuntimeMethodInfo GetParentDefinition()
override bool IsGenericMethod
override MethodInfo GetGenericMethodDefinition()
unsafe override MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
MetadataImport MetadataImport
override int MetadataToken
override Type ResolveType(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
override int MetadataToken
RuntimeModule GetRuntimeModule()
RuntimeModule GetRuntimeModule()
override int MetadataToken
override bool IsAssignableFrom([NotNullWhen(true)] TypeInfo typeInfo)
override int MetadataToken
override bool ContainsGenericParameters
RuntimeModule GetRuntimeModule()
static string Format(string resourceFormat, object p1)
static string Format_AttributeUsage
static string RFLCT_InvalidPropFail
static string RFLCT_InvalidFieldFail
static Binder DefaultBinder
static readonly Type[] EmptyTypes
RuntimeTypeHandle ResolveTypeHandle(int typeToken)
RuntimeMethodHandle ResolveMethodHandle(int methodToken)
static RuntimeMethodHandleInternal EmptyHandle
static Interop.BOOL IsCAVisibleFromDecoratedType(QCallTypeHandle attrTypeHandle, RuntimeMethodHandleInternal attrCtor, QCallTypeHandle sourceTypeHandle, QCallModule sourceModule)
IRuntimeMethodInfo GetMethodInfo()