12 [__DynamicallyInvokable]
17 private RuntimeModule m_scope;
21 private CustomAttributeCtorParameter[] m_ctorParams;
23 private CustomAttributeNamedParameter[] m_namedParams;
31 [__DynamicallyInvokable]
34 [__DynamicallyInvokable]
55 [__DynamicallyInvokable]
58 [__DynamicallyInvokable]
61 if (m_typedCtorArgs ==
null)
64 for (
int i = 0; i < array.Length; i++)
66 CustomAttributeEncodedArgument customAttributeEncodedArgument = m_ctorParams[i].CustomAttributeEncodedArgument;
69 m_typedCtorArgs =
Array.AsReadOnly(array);
71 return m_typedCtorArgs;
77 [__DynamicallyInvokable]
80 [__DynamicallyInvokable]
83 if (m_namedArgs ==
null)
85 if (m_namedParams ==
null)
90 for (
int i = 0; i < m_namedParams.Length; i++)
92 if (m_namedParams[i].EncodedArgument.CustomAttributeType.EncodedType != 0)
100 for (; j < m_namedParams.Length; j++)
102 if (m_namedParams[j].EncodedArgument.CustomAttributeType.EncodedType != 0)
107 m_namedArgs =
Array.AsReadOnly(array);
169 [SecuritySafeCritical]
174 Attribute[] customAttributes2 = PseudoCustomAttribute.
GetCustomAttributes(target, typeof(
object) as RuntimeType, includeSecCa:
true, out count);
177 return customAttributes;
180 customAttributes.
CopyTo(array, count);
181 for (
int i = 0; i < count; i++)
185 return Array.AsReadOnly(array);
188 [SecuritySafeCritical]
193 Attribute[] customAttributes2 = PseudoCustomAttribute.
GetCustomAttributes(target, typeof(
object) as RuntimeType, out count);
196 return customAttributes;
199 customAttributes.
CopyTo(array, count);
200 for (
int i = 0; i < count; i++)
204 return Array.AsReadOnly(array);
207 [SecuritySafeCritical]
212 Attribute[] customAttributes2 = PseudoCustomAttribute.GetCustomAttributes(target, typeof(
object) as RuntimeType, includeSecCa:
true, out count);
215 return customAttributes;
218 customAttributes.
CopyTo(array, count);
219 for (
int i = 0; i < count; i++)
223 return Array.AsReadOnly(array);
226 [SecuritySafeCritical]
232 [SecuritySafeCritical]
238 [SecuritySafeCritical]
244 [SecuritySafeCritical]
247 if (target.IsResource())
254 [SecuritySafeCritical]
259 Attribute[] customAttributes2 = PseudoCustomAttribute.GetCustomAttributes(target, typeof(
object) as RuntimeType, includeSecCa:
false, out count);
262 return customAttributes;
265 customAttributes.
CopyTo(array, count);
266 for (
int i = 0; i < count; i++)
270 return Array.AsReadOnly(array);
273 [SecuritySafeCritical]
278 Attribute[] customAttributes2 = PseudoCustomAttribute.GetCustomAttributes(target, typeof(
object) as RuntimeType, out count);
281 return customAttributes;
284 customAttributes.
CopyTo(array, count);
285 for (
int i = 0; i < count; i++)
289 return Array.AsReadOnly(array);
292 private static CustomAttributeEncoding TypeToCustomAttributeEncoding(RuntimeType type)
294 if (type == (RuntimeType)typeof(
int))
296 return CustomAttributeEncoding.Int32;
300 return CustomAttributeEncoding.Enum;
302 if (type == (RuntimeType)typeof(
string))
304 return CustomAttributeEncoding.String;
306 if (type == (RuntimeType)typeof(Type))
308 return CustomAttributeEncoding.Type;
310 if (type == (RuntimeType)typeof(
object))
312 return CustomAttributeEncoding.Object;
316 return CustomAttributeEncoding.Array;
318 if (type == (RuntimeType)typeof(
char))
320 return CustomAttributeEncoding.Char;
322 if (type == (RuntimeType)typeof(
bool))
324 return CustomAttributeEncoding.Boolean;
326 if (type == (RuntimeType)typeof(
byte))
328 return CustomAttributeEncoding.Byte;
330 if (type == (RuntimeType)typeof(sbyte))
332 return CustomAttributeEncoding.SByte;
334 if (type == (RuntimeType)typeof(
short))
336 return CustomAttributeEncoding.Int16;
338 if (type == (RuntimeType)typeof(ushort))
340 return CustomAttributeEncoding.UInt16;
342 if (type == (RuntimeType)typeof(uint))
344 return CustomAttributeEncoding.UInt32;
346 if (type == (RuntimeType)typeof(
long))
348 return CustomAttributeEncoding.Int64;
350 if (type == (RuntimeType)typeof(ulong))
352 return CustomAttributeEncoding.UInt64;
354 if (type == (RuntimeType)typeof(
float))
356 return CustomAttributeEncoding.Float;
358 if (type == (RuntimeType)typeof(
double))
360 return CustomAttributeEncoding.Double;
362 if (type == (RuntimeType)typeof(Enum))
364 return CustomAttributeEncoding.Object;
368 return CustomAttributeEncoding.Object;
370 if (type.IsInterface)
372 return CustomAttributeEncoding.Object;
374 if (type.IsValueType)
376 return CustomAttributeEncoding.Undefined;
378 throw new ArgumentException(Environment.GetResourceString(
"Argument_InvalidKindOfTypeForCA"),
"type");
381 private static CustomAttributeType InitCustomAttributeType(RuntimeType parameterType)
383 CustomAttributeEncoding customAttributeEncoding = TypeToCustomAttributeEncoding(parameterType);
384 CustomAttributeEncoding customAttributeEncoding2 = CustomAttributeEncoding.Undefined;
385 CustomAttributeEncoding encodedEnumType = CustomAttributeEncoding.Undefined;
386 string enumName =
null;
387 if (customAttributeEncoding == CustomAttributeEncoding.Array)
389 parameterType = (RuntimeType)parameterType.GetElementType();
390 customAttributeEncoding2 = TypeToCustomAttributeEncoding(parameterType);
392 if (customAttributeEncoding == CustomAttributeEncoding.Enum || customAttributeEncoding2 == CustomAttributeEncoding.Enum)
394 encodedEnumType = TypeToCustomAttributeEncoding((RuntimeType)
Enum.GetUnderlyingType(parameterType));
395 enumName = parameterType.AssemblyQualifiedName;
397 return new CustomAttributeType(customAttributeEncoding, customAttributeEncoding2, encodedEnumType, enumName);
403 CustomAttributeRecord[] customAttributeRecords = GetCustomAttributeRecords(module, tkTarget);
405 for (
int i = 0; i < customAttributeRecords.Length; i++)
409 return Array.AsReadOnly(array);
413 internal static CustomAttributeRecord[] GetCustomAttributeRecords(RuntimeModule module,
int targetToken)
415 MetadataImport metadataImport = module.MetadataImport;
416 metadataImport.EnumCustomAttributes(targetToken, out MetadataEnumResult result);
417 CustomAttributeRecord[] array =
new CustomAttributeRecord[result.Length];
418 for (
int i = 0; i < array.Length; i++)
420 metadataImport.GetCustomAttributeProps(result[i], out array[i].tkCtor.Value, out array[i].blob);
427 for (
int i = 0; i < attrs.
Count; i++)
431 return attrs[i].ConstructorArguments[parameter];
434 return default(CustomAttributeTypedArgument);
442 [SecuritySafeCritical]
446 m_ctor = (RuntimeConstructorInfo)RuntimeType.GetMethodBase(scope, caRecord.tkCtor);
447 ParameterInfo[] parametersNoCopy = m_ctor.GetParametersNoCopy();
448 m_ctorParams =
new CustomAttributeCtorParameter[parametersNoCopy.Length];
449 for (
int i = 0; i < parametersNoCopy.Length; i++)
451 m_ctorParams[i] =
new CustomAttributeCtorParameter(InitCustomAttributeType((RuntimeType)parametersNoCopy[i].ParameterType));
455 m_namedParams =
new CustomAttributeNamedParameter[properties.Length + fields.Length];
456 for (
int j = 0; j < fields.Length; j++)
458 m_namedParams[j] =
new CustomAttributeNamedParameter(fields[j].Name, CustomAttributeEncoding.Field, InitCustomAttributeType((RuntimeType)fields[j].FieldType));
460 for (
int k = 0; k < properties.Length; k++)
462 m_namedParams[k + fields.Length] =
new CustomAttributeNamedParameter(properties[k].Name, CustomAttributeEncoding.Property, InitCustomAttributeType((RuntimeType)properties[k].PropertyType));
464 m_members =
new MemberInfo[fields.Length + properties.Length];
465 fields.CopyTo(m_members, 0);
466 properties.CopyTo(m_members, fields.Length);
467 CustomAttributeEncodedArgument.ParseAttributeArguments(caRecord.blob, ref m_ctorParams, ref m_namedParams, m_scope);
498 m_typedCtorArgs = Array.AsReadOnly(
new CustomAttributeTypedArgument[1]
500 new CustomAttributeTypedArgument(dllImport.
Value)
502 m_namedArgs = Array.AsReadOnly(
new CustomAttributeNamedArgument[8]
504 new CustomAttributeNamedArgument(typeFromHandle.GetField(
"EntryPoint"), dllImport.
EntryPoint),
505 new CustomAttributeNamedArgument(typeFromHandle.GetField(
"CharSet"), dllImport.
CharSet),
506 new CustomAttributeNamedArgument(typeFromHandle.GetField(
"ExactSpelling"), dllImport.
ExactSpelling),
507 new CustomAttributeNamedArgument(typeFromHandle.GetField(
"SetLastError"), dllImport.
SetLastError),
508 new CustomAttributeNamedArgument(typeFromHandle.GetField(
"PreserveSig"), dllImport.
PreserveSig),
509 new CustomAttributeNamedArgument(typeFromHandle.GetField(
"CallingConvention"), dllImport.
CallingConvention),
510 new CustomAttributeNamedArgument(typeFromHandle.GetField(
"BestFitMapping"), dllImport.
BestFitMapping),
511 new CustomAttributeNamedArgument(typeFromHandle.GetField(
"ThrowOnUnmappableChar"), dllImport.
ThrowOnUnmappableChar)
518 m_typedCtorArgs = Array.AsReadOnly(
new CustomAttributeTypedArgument[1]
520 new CustomAttributeTypedArgument(fieldOffset.
Value)
522 m_namedArgs = Array.AsReadOnly(
new CustomAttributeNamedArgument[0]);
529 m_typedCtorArgs = Array.AsReadOnly(
new CustomAttributeTypedArgument[1]
531 new CustomAttributeTypedArgument(marshalAs.
Value)
552 CustomAttributeNamedArgument[] array =
new CustomAttributeNamedArgument[num];
554 array[num++] =
new CustomAttributeNamedArgument(typeFromHandle.GetField(
"ArraySubType"), marshalAs.
ArraySubType);
555 array[num++] =
new CustomAttributeNamedArgument(typeFromHandle.GetField(
"SizeParamIndex"), marshalAs.
SizeParamIndex);
556 array[num++] =
new CustomAttributeNamedArgument(typeFromHandle.GetField(
"SizeConst"), marshalAs.
SizeConst);
557 array[num++] =
new CustomAttributeNamedArgument(typeFromHandle.GetField(
"IidParameterIndex"), marshalAs.
IidParameterIndex);
558 array[num++] =
new CustomAttributeNamedArgument(typeFromHandle.GetField(
"SafeArraySubType"), marshalAs.
SafeArraySubType);
561 array[num++] =
new CustomAttributeNamedArgument(typeFromHandle.GetField(
"MarshalType"), marshalAs.
MarshalType);
565 array[num++] =
new CustomAttributeNamedArgument(typeFromHandle.GetField(
"MarshalTypeRef"), marshalAs.
MarshalTypeRef);
569 array[num++] =
new CustomAttributeNamedArgument(typeFromHandle.GetField(
"MarshalCookie"), marshalAs.
MarshalCookie);
573 array[num++] =
new CustomAttributeNamedArgument(typeFromHandle.GetField(
"SafeArrayUserDefinedSubType"), marshalAs.
SafeArrayUserDefinedSubType);
575 m_namedArgs = Array.AsReadOnly(array);
586 m_typedCtorArgs = Array.AsReadOnly(
new CustomAttributeTypedArgument[1]
588 new CustomAttributeTypedArgument(typeof(Type), forwardedTo.
Destination)
590 CustomAttributeNamedArgument[] array =
new CustomAttributeNamedArgument[0];
591 m_namedArgs = Array.AsReadOnly(array);
594 private void Init(
object pca)
597 m_typedCtorArgs = Array.AsReadOnly(
new CustomAttributeTypedArgument[0]);
598 m_namedArgs = Array.AsReadOnly(
new CustomAttributeNamedArgument[0]);
622 return base.GetHashCode();
Obtains information about the attributes of a member and provides access to member metadata.
Performs reflection on a module.
FieldInfo [] GetFields()
Returns all the public fields of the current T:System.Type.
Discovers the attributes of a parameter and provides access to parameter metadata.
string MarshalCookie
Provides additional information to a custom marshaler.
virtual IList< CustomAttributeNamedArgument > NamedArguments
Gets the list of named arguments specified for the attribute instance represented by the T:System....
bool PreserveSig
Indicates whether unmanaged methods that have HRESULT or retval return values are directly translated...
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
bool BestFitMapping
Enables or disables best-fit mapping behavior when converting Unicode characters to ANSI characters.
Represents a named argument of a custom attribute in the reflection-only context.
static IList< CustomAttributeData > GetCustomAttributes(ParameterInfo target)
Returns a list of T:System.Reflection.CustomAttributeData objects representing data about the attribu...
bool ThrowOnUnmappableChar
Enables or disables the throwing of an exception on an unmappable Unicode character that is converted...
short SizeParamIndex
Indicates the zero-based parameter that contains the count of array elements, similar to size_is in C...
abstract string FullName
Gets the fully qualified name of the type, including its namespace but not its assembly.
CallingConvention CallingConvention
Indicates the calling convention of an entry point.
VarEnum SafeArraySubType
Indicates the element type of the F:System.Runtime.InteropServices.UnmanagedType.SafeArray.
Discovers the attributes of a class constructor and provides access to constructor metadata.
Represents the base class for custom attributes.
abstract PropertyInfo [] GetProperties(BindingFlags bindingAttr)
When overridden in a derived class, searches for the properties of the current T:System....
BindingFlags
Specifies flags that control binding and the way in which the search for members and types is conduct...
Type MarshalTypeRef
Implements F:System.Runtime.InteropServices.MarshalAsAttribute.MarshalType as a type.
int Value
Gets the offset from the beginning of the structure to the beginning of the field.
Provides access to custom attribute data for assemblies, modules, types, members and parameters that ...
bool SetLastError
Indicates whether the callee calls the SetLastError Win32 API function before returning from the attr...
static IList< CustomAttributeData > GetCustomAttributes(MemberInfo target)
Returns a list of T:System.Reflection.CustomAttributeData objects representing data about the attribu...
void CopyTo(T[] array, int arrayIndex)
Copies the elements of the T:System.Collections.Generic.ICollection`1 to an T:System....
CustomAttributeData()
Initializes a new instance of the T:System.Reflection.CustomAttributeData class.
virtual IList< CustomAttributeData > GetCustomAttributesData()
Returns a list of T:System.Reflection.CustomAttributeData objects for the current parameter,...
Indicates that the attributed method is exposed by an unmanaged dynamic-link library (DLL) as a stati...
Indicates how to marshal the data between managed and unmanaged code.
Type AttributeType
Gets the type of the attribute.
override string ToString()
Returns a string representation of the custom attribute.
Represents an argument of a custom attribute in the reflection-only context, or an element of an arra...
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
int SizeConst
Indicates the number of elements in the fixed-length array or the number of characters (not bytes) in...
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Represents type declarations: class types, interface types, array types, value types,...
Type SafeArrayUserDefinedSubType
Indicates the user-defined element type of the F:System.Runtime.InteropServices.UnmanagedType....
Indicates the physical position of fields within the unmanaged representation of a class or structure...
string Value
Gets the name of the DLL file that contains the entry point.
virtual IList< CustomAttributeData > GetCustomAttributesData()
Returns information about the attributes that have been applied to the current T:System....
UnmanagedType Value
Gets the T:System.Runtime.InteropServices.UnmanagedType value the data is to be marshaled as.
Type DeclaringType
Provides COM objects with version-independent access to the P:System.Reflection.MemberInfo....
Represents a collection of objects that can be individually accessed by index.
bool ExactSpelling
Controls whether the F:System.Runtime.InteropServices.DllImportAttribute.CharSet field causes the com...
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
static Attribute [] GetCustomAttributes(MemberInfo element, Type type)
Retrieves an array of the custom attributes applied to a member of a type. Parameters specify the mem...
int Count
Gets the number of elements contained in the T:System.Collections.Generic.ICollection`1.
Specifies a destination T:System.Type in another assembly.
virtual ConstructorInfo Constructor
Gets a T:System.Reflection.ConstructorInfo object that represents the constructor that would have ini...
CharSet CharSet
Indicates how to marshal string parameters to the method and controls name mangling.
Attribute can be applied to an enumeration.
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
virtual IList< CustomAttributeData > GetCustomAttributesData()
Returns a list of T:System.Reflection.CustomAttributeData objects representing data about the attribu...
static IList< CustomAttributeData > GetCustomAttributes(Assembly target)
Returns a list of T:System.Reflection.CustomAttributeData objects representing data about the attribu...
override bool Equals(object obj)
Returns a value that indicates whether this instance is equal to a specified object.
string EntryPoint
Indicates the name or ordinal of the DLL entry point to be called.
Specifies that the class can be serialized.
override int GetHashCode()
Serves as a hash function for a particular type.
Provides information about a specific culture (called a locale for unmanaged code development)....
ConstructorInfo [] GetConstructors()
Returns all the public constructors defined for the current T:System.Type.
virtual IList< CustomAttributeTypedArgument > ConstructorArguments
Gets the list of positional arguments specified for the attribute instance represented by the T:Syste...
UnmanagedType ArraySubType
Specifies the element type of the unmanaged F:System.Runtime.InteropServices.UnmanagedType....
int IidParameterIndex
Specifies the parameter index of the unmanaged iid_is attribute used by COM.
Type Destination
Gets the destination T:System.Type in another assembly.
string MarshalType
Specifies the fully qualified name of a custom marshaler.
static IList< CustomAttributeData > GetCustomAttributes(Module target)
Returns a list of T:System.Reflection.CustomAttributeData objects representing data about the attribu...
virtual IList< CustomAttributeData > GetCustomAttributesData()
Returns a list of T:System.Reflection.CustomAttributeData objects for the current module,...