10 [AttributeUsage(
AttributeTargets.All, Inherited =
true, AllowMultiple =
false)]
14 [__DynamicallyInvokable]
19 public virtual object TypeId => GetType();
30 CopyToArrayList(list, array, types);
31 Type[] indexParameterTypes = GetIndexParameterTypes(element);
32 PropertyInfo parentDefinition = GetParentDefinition(element, indexParameterTypes);
33 while (parentDefinition !=
null)
36 AddAttributesToList(list, array, types);
37 parentDefinition = GetParentDefinition(parentDefinition, indexParameterTypes);
39 Array array2 = CreateAttributeArrayHelper(type, list.Count);
40 Array.Copy(list.ToArray(), 0, array2, 0, list.Count);
44 private static bool InternalIsDefined(
PropertyInfo element, Type attributeType,
bool inherit)
46 if (element.
IsDefined(attributeType, inherit))
52 AttributeUsageAttribute attributeUsageAttribute = InternalGetAttributeUsage(attributeType);
53 if (!attributeUsageAttribute.Inherited)
57 Type[] indexParameterTypes = GetIndexParameterTypes(element);
58 PropertyInfo parentDefinition = GetParentDefinition(element, indexParameterTypes);
59 while (parentDefinition !=
null)
61 if (parentDefinition.
IsDefined(attributeType, inherit:
false))
65 parentDefinition = GetParentDefinition(parentDefinition, indexParameterTypes);
73 MethodInfo methodInfo =
property.GetGetMethod(nonPublic:
true);
74 if (methodInfo ==
null)
76 methodInfo =
property.GetSetMethod(nonPublic:
true);
78 RuntimeMethodInfo runtimeMethodInfo = methodInfo as RuntimeMethodInfo;
79 if (runtimeMethodInfo !=
null)
81 runtimeMethodInfo = runtimeMethodInfo.GetParentDefinition();
82 if (runtimeMethodInfo !=
null)
90 private static Attribute[] InternalGetCustomAttributes(
EventInfo element, Type type,
bool inherit)
97 CopyToArrayList(list, array, types);
98 EventInfo parentDefinition = GetParentDefinition(element);
99 while (parentDefinition !=
null)
102 AddAttributesToList(list, array, types);
103 parentDefinition = GetParentDefinition(parentDefinition);
105 Array array2 = CreateAttributeArrayHelper(type, list.Count);
106 Array.Copy(list.ToArray(), 0, array2, 0, list.Count);
115 RuntimeMethodInfo runtimeMethodInfo = addMethod as RuntimeMethodInfo;
116 if (runtimeMethodInfo !=
null)
118 runtimeMethodInfo = runtimeMethodInfo.GetParentDefinition();
119 if (runtimeMethodInfo !=
null)
127 private static bool InternalIsDefined(
EventInfo element, Type attributeType,
bool inherit)
129 if (element.
IsDefined(attributeType, inherit))
135 AttributeUsageAttribute attributeUsageAttribute = InternalGetAttributeUsage(attributeType);
136 if (!attributeUsageAttribute.Inherited)
140 EventInfo parentDefinition = GetParentDefinition(element);
141 while (parentDefinition !=
null)
143 if (parentDefinition.
IsDefined(attributeType, inherit:
false))
147 parentDefinition = GetParentDefinition(parentDefinition);
155 RuntimeMethodInfo runtimeMethodInfo = param.
Member as RuntimeMethodInfo;
156 if (runtimeMethodInfo !=
null)
158 runtimeMethodInfo = runtimeMethodInfo.GetParentDefinition();
159 if (runtimeMethodInfo !=
null)
161 ParameterInfo[] parameters = runtimeMethodInfo.GetParameters();
176 for (
int i = 0; i < customAttributes.Length; i++)
178 Type type2 = customAttributes[i].GetType();
179 AttributeUsageAttribute attributeUsageAttribute = InternalGetAttributeUsage(type2);
180 if (!attributeUsageAttribute.AllowMultiple)
186 array = ((customAttributes.Length != 0) ? ((
Attribute[])customAttributes) : CreateAttributeArrayHelper(type, 0));
195 for (
ParameterInfo parentDefinition = GetParentDefinition(param); parentDefinition !=
null; parentDefinition = GetParentDefinition(parentDefinition))
199 for (
int j = 0; j < customAttributes.Length; j++)
201 Type type3 = customAttributes[j].GetType();
202 AttributeUsageAttribute attributeUsageAttribute2 = InternalGetAttributeUsage(type3);
203 if (attributeUsageAttribute2.Inherited && !list.Contains(type3))
205 if (!attributeUsageAttribute2.AllowMultiple)
213 customAttributes[j] =
null;
216 Attribute[] array2 = CreateAttributeArrayHelper(type, num);
218 for (
int k = 0; k < customAttributes.Length; k++)
220 if (customAttributes[k] !=
null)
222 array2[num] = (
Attribute)customAttributes[k];
227 array = CreateAttributeArrayHelper(type, array3.Length + num);
228 Array.Copy(array3, array, array3.Length);
229 int num2 = array3.Length;
230 for (
int l = 0; l < array2.Length; l++)
232 array[num2 + l] = array2[l];
238 private static bool InternalParamIsDefined(
ParameterInfo param, Type type,
bool inherit)
240 if (param.
IsDefined(type, inherit:
false))
248 for (
ParameterInfo parentDefinition = GetParentDefinition(param); parentDefinition !=
null; parentDefinition = GetParentDefinition(parentDefinition))
251 for (
int i = 0; i < customAttributes.Length; i++)
253 Type type2 = customAttributes[i].GetType();
254 AttributeUsageAttribute attributeUsageAttribute = InternalGetAttributeUsage(type2);
255 if (customAttributes[i] is
Attribute && attributeUsageAttribute.Inherited)
266 for (
int i = 0; i < attributes.Length; i++)
268 attributeList.
Add(attributes[i]);
269 Type type = attributes[i].GetType();
272 types[type] = InternalGetAttributeUsage(type);
280 if (indexParameters.Length != 0)
282 Type[] array =
new Type[indexParameters.Length];
283 for (
int i = 0; i < indexParameters.Length; i++)
289 return Array.Empty<
Type>();
294 for (
int i = 0; i < attributes.Length; i++)
296 Type type = attributes[i].GetType();
297 AttributeUsageAttribute value =
null;
301 value = (types[type] = InternalGetAttributeUsage(type));
304 attributeList.
Add(attributes[i]);
307 else if (value.Inherited && value.AllowMultiple)
309 attributeList.
Add(attributes[i]);
314 private static AttributeUsageAttribute InternalGetAttributeUsage(Type type)
316 object[] customAttributes = type.GetCustomAttributes(typeof(AttributeUsageAttribute), inherit:
false);
317 if (customAttributes.Length == 1)
319 return (AttributeUsageAttribute)customAttributes[0];
321 if (customAttributes.Length == 0)
323 return AttributeUsageAttribute.Default;
325 throw new FormatException(Environment.GetResourceString(
"Format_AttributeUsage", type));
328 [SecuritySafeCritical]
329 private static Attribute[] CreateAttributeArrayHelper(Type elementType,
int elementCount)
331 return (
Attribute[])Array.UnsafeCreateInstance(elementType, elementCount);
345 [__DynamicallyInvokable]
363 [__DynamicallyInvokable]
381 return InternalGetCustomAttributes((
PropertyInfo)element, type, inherit);
383 return InternalGetCustomAttributes((
EventInfo)element, type, inherit);
397 [__DynamicallyInvokable]
412 [__DynamicallyInvokable]
441 [__DynamicallyInvokable]
444 return IsDefined(element, attributeType, inherit:
true);
459 [__DynamicallyInvokable]
466 if (attributeType ==
null)
477 return InternalIsDefined((
PropertyInfo)element, attributeType, inherit);
479 return InternalIsDefined((
EventInfo)element, attributeType, inherit);
481 return element.
IsDefined(attributeType, inherit);
497 [__DynamicallyInvokable]
516 [__DynamicallyInvokable]
520 if (customAttributes ==
null || customAttributes.Length == 0)
524 if (customAttributes.Length == 1)
526 return customAttributes[0];
537 [__DynamicallyInvokable]
552 [__DynamicallyInvokable]
568 [__DynamicallyInvokable]
575 if (attributeType ==
null)
583 if (element.
Member ==
null)
590 return InternalParamGetCustomAttributes(element, attributeType, inherit);
603 [__DynamicallyInvokable]
610 if (element.
Member ==
null)
617 return InternalParamGetCustomAttributes(element,
null, inherit);
631 [__DynamicallyInvokable]
634 return IsDefined(element, attributeType, inherit:
true);
649 [__DynamicallyInvokable]
656 if (attributeType ==
null)
668 return InternalParamIsDefined(element, attributeType, inherit);
670 return element.
IsDefined(attributeType, inherit:
false);
672 return element.
IsDefined(attributeType, inherit:
false);
688 [__DynamicallyInvokable]
705 [__DynamicallyInvokable]
709 if (customAttributes ==
null || customAttributes.Length == 0)
713 if (customAttributes.Length == 0)
717 if (customAttributes.Length == 1)
719 return customAttributes[0];
777 if (attributeType ==
null)
799 return IsDefined(element, attributeType, inherit:
false);
818 if (attributeType ==
null)
826 return element.
IsDefined(attributeType, inherit:
false);
856 if (customAttributes ==
null || customAttributes.Length == 0)
860 if (customAttributes.Length == 1)
862 return customAttributes[0];
875 [__DynamicallyInvokable]
896 if (attributeType ==
null)
912 [__DynamicallyInvokable]
942 [__DynamicallyInvokable]
945 return IsDefined(element, attributeType, inherit:
true);
964 if (attributeType ==
null)
972 return element.
IsDefined(attributeType, inherit:
false);
984 [__DynamicallyInvokable]
1003 if (customAttributes ==
null || customAttributes.Length == 0)
1007 if (customAttributes.Length == 1)
1009 return customAttributes[0];
1015 [__DynamicallyInvokable]
1024 [SecuritySafeCritical]
1025 [__DynamicallyInvokable]
1032 RuntimeType runtimeType = (RuntimeType)GetType();
1033 RuntimeType left = (RuntimeType)obj.GetType();
1034 if (left != runtimeType)
1039 for (
int i = 0; i < fields.Length; i++)
1041 object thisValue = ((RtFieldInfo)fields[i]).UnsafeGetValue(
this);
1042 object thatValue = ((RtFieldInfo)fields[i]).UnsafeGetValue(obj);
1043 if (!AreFieldValuesEqual(thisValue, thatValue))
1051 private static bool AreFieldValuesEqual(
object thisValue,
object thatValue)
1053 if (thisValue ==
null && thatValue ==
null)
1057 if (thisValue ==
null || thatValue ==
null)
1061 if (thisValue.GetType().IsArray)
1063 if (!thisValue.GetType().Equals(thatValue.GetType()))
1067 Array array = thisValue as Array;
1068 Array array2 = thatValue as Array;
1069 if (array.Length != array2.Length)
1073 for (
int i = 0; i < array.Length; i++)
1075 if (!AreFieldValuesEqual(array.GetValue(i), array2.GetValue(i)))
1081 else if (!thisValue.Equals(thatValue))
1090 [SecuritySafeCritical]
1091 [__DynamicallyInvokable]
1094 Type type = GetType();
1097 for (
int i = 0; i < fields.Length; i++)
1099 object obj2 = ((RtFieldInfo)fields[i]).UnsafeGetValue(
this);
1100 if (obj2 !=
null && !obj2.GetType().IsArray)
1144 throw new NotImplementedException();
1156 throw new NotImplementedException();
1169 void _Attribute.
Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid,
short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
1171 throw new NotImplementedException();
Obtains information about the attributes of a member and provides access to member metadata.
static Attribute [] GetCustomAttributes(ParameterInfo element, Type attributeType, bool inherit)
Retrieves an array of the custom attributes applied to a method parameter. Parameters specify the met...
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.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
virtual bool Match(object obj)
When overridden in a derived class, returns a value that indicates whether this instance equals a spe...
virtual object [] GetCustomAttributes(bool inherit)
Returns all custom attributes.
static Attribute [] GetCustomAttributes(ParameterInfo element)
Retrieves an array of the custom attributes applied to a method parameter. A parameter specifies the ...
override int GetHashCode()
Returns the hash code for this instance.
abstract Type DeclaringType
Gets the class that declares this member.
static bool IsDefined(Assembly element, Type attributeType)
Determines whether any custom attributes are applied to an assembly. Parameters specify the assembly,...
Discovers the attributes of a method and provides access to method metadata.
virtual bool IsDefined(Type attributeType, bool inherit)
Indicates whether or not a specified attribute has been applied to the assembly.
void Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
Provides access to properties and methods exposed by an object.
static Attribute GetCustomAttribute(Module element, Type attributeType, bool inherit)
Retrieves a custom attribute applied to a module. Parameters specify the module, the type of the cust...
Represents the base class for custom attributes.
Discovers the attributes of a field and provides access to field metadata.
static Attribute [] GetCustomAttributes(MemberInfo element)
Retrieves an array of the custom attributes applied to a member of a type. A parameter specifies the ...
BindingFlags
Specifies flags that control binding and the way in which the search for members and types is conduct...
static Attribute [] GetCustomAttributes(Module element, Type attributeType)
Retrieves an array of the custom attributes applied to a module. Parameters specify the module,...
static Attribute [] GetCustomAttributes(Assembly element)
Retrieves an array of the custom attributes applied to an assembly. A parameter specifies the assembl...
abstract object [] GetCustomAttributes(bool inherit)
When overridden in a derived class, returns an array of all custom attributes applied to this member.
virtual object TypeId
When implemented in a derived class, gets a unique identifier for this T:System.Attribute.
static bool IsDefined(MemberInfo element, Type attributeType, bool inherit)
Determines whether any custom attributes are applied to a member of a type. Parameters specify the me...
static Attribute [] GetCustomAttributes(Assembly element, Type attributeType, bool inherit)
Retrieves an array of the custom attributes applied to an assembly. Parameters specify the assembly,...
static Attribute GetCustomAttribute(ParameterInfo element, Type attributeType, bool inherit)
Retrieves a custom attribute applied to a method parameter. Parameters specify the method parameter,...
virtual MemberInfo Member
Gets a value indicating the member in which the parameter is implemented.
static bool IsDefined(ParameterInfo element, Type attributeType, bool inherit)
Determines whether any custom attributes are applied to a method parameter. Parameters specify the me...
virtual object [] GetCustomAttributes(bool inherit)
Gets all the custom attributes defined on this parameter.
virtual object [] GetCustomAttributes(bool inherit)
Gets all the custom attributes for this assembly.
bool ContainsKey(TKey key)
Determines whether the T:System.Collections.Generic.Dictionary`2 contains the specified key.
PropertyInfo GetProperty(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
Searches for the specified property whose parameters match the specified argument types and modifiers...
Exposes the T:System.Attribute class to unmanaged code.
virtual bool IsSubclassOf(Type c)
Determines whether the current T:System.Type derives from the specified T:System.Type.
static Attribute GetCustomAttribute(MemberInfo element, Type attributeType, bool inherit)
Retrieves a custom attribute applied to a member of a type. Parameters specify the member,...
void Add(T item)
Adds an object to the end of the T:System.Collections.Generic.List`1.
static bool IsDefined(Module element, Type attributeType, bool inherit)
Determines whether any custom attributes are applied to a module. Parameters specify the module,...
Provides information about, and means to manipulate, the current environment and platform....
abstract bool IsDefined(Type attributeType, bool inherit)
When overridden in a derived class, indicates whether one or more attributes of the specified type or...
static Attribute [] GetCustomAttributes(Assembly element, bool inherit)
Retrieves an array of the custom attributes applied to an assembly. Parameters specify the assembly,...
static Attribute [] GetCustomAttributes(Assembly element, Type attributeType)
Retrieves an array of the custom attributes applied to an assembly. Parameters specify the assembly,...
EventInfo GetEvent(string name)
Returns the T:System.Reflection.EventInfo object representing the specified public event.
void GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
Maps a set of names to a corresponding set of dispatch identifiers.
static bool IsDefined(ParameterInfo element, Type attributeType)
Determines whether any custom attributes are applied to a method parameter. Parameters specify the me...
static Attribute GetCustomAttribute(ParameterInfo element, Type attributeType)
Retrieves a custom attribute applied to a method parameter. Parameters specify the method parameter,...
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
static Attribute [] GetCustomAttributes(Module element, Type attributeType, bool inherit)
Retrieves an array of the custom attributes applied to a module. Parameters specify the module,...
Discovers the attributes of an event and provides access to event metadata.
static Attribute [] GetCustomAttributes(Module element, bool inherit)
Retrieves an array of the custom attributes applied to a module. Parameters specify the module,...
Represents type declarations: class types, interface types, array types, value types,...
Type DeclaringType
Provides COM objects with version-independent access to the P:System.Reflection.MemberInfo....
static bool IsDefined(Module element, Type attributeType)
Determines whether any custom attributes of a specified type are applied to a module....
static bool IsDefined(Assembly element, Type attributeType, bool inherit)
Determines whether any custom attributes are applied to an assembly. Parameters specify the assembly,...
static Attribute [] GetCustomAttributes(Module element)
Retrieves an array of the custom attributes applied to a module. A parameter specifies the module.
abstract string Name
Gets the name of the current member.
abstract Type PropertyType
Gets the type of this property.
abstract MethodInfo GetAddMethod(bool nonPublic)
When overridden in a derived class, retrieves the MethodInfo object for the M:System....
AttributeTargets
Specifies the application elements on which it is valid to apply an attribute.
Represents a collection of keys and values.To browse the .NET Framework source code for this type,...
void GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
Retrieves the type information for an object, which can be used to get the type information for an in...
Discovers the attributes of a property and provides access to property metadata.
virtual int Position
Gets the zero-based position of the parameter in the formal parameter list.
The exception that is thrown when one of the arguments provided to a method is not valid.
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...
abstract ParameterInfo [] GetIndexParameters()
When overridden in a derived class, returns an array of all the index parameters for the property.
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
static Attribute GetCustomAttribute(Assembly element, Type attributeType)
Retrieves a custom attribute applied to a specified assembly. Parameters specify the assembly and the...
static Attribute [] GetCustomAttributes(ParameterInfo element, bool inherit)
Retrieves an array of the custom attributes applied to a method parameter. Parameters specify the met...
static Attribute [] GetCustomAttributes(ParameterInfo element, Type attributeType)
Retrieves an array of the custom attributes applied to a method parameter. Parameters specify the met...
override int GetHashCode()
Returns the hash code for this instance.
Specifies that the class can be serialized.
virtual Type ParameterType
Gets the Type of this parameter.
abstract MemberTypes MemberType
When overridden in a derived class, gets a T:System.Reflection.MemberTypes value indicating the type ...
ClassInterfaceType
Identifies the type of class interface that is generated for a class.
virtual bool IsDefined(Type attributeType, bool inherit)
Determines whether the custom attribute of the specified type or its derived types is applied to this...
static Attribute GetCustomAttribute(Assembly element, Type attributeType, bool inherit)
Retrieves a custom attribute applied to an assembly. Parameters specify the assembly,...
virtual bool IsDefined(Type attributeType, bool inherit)
Returns a value that indicates whether the specified attribute type has been applied to this module.
static bool IsDefined(MemberInfo element, Type attributeType)
Determines whether any custom attributes are applied to a member of a type. Parameters specify the me...
Attribute()
Initializes a new instance of the T:System.Attribute class.
override bool Equals(object obj)
Returns a value that indicates whether this instance is equal to a specified object.
MemberTypes
Marks each type of member that is defined as a derived class of T:System.Reflection....
void GetTypeInfoCount(out uint pcTInfo)
Retrieves the number of type information interfaces that an object provides (either 0 or 1).
The exception that is thrown when binding to a member results in more than one member matching the bi...
static Attribute GetCustomAttribute(Module element, Type attributeType)
Retrieves a custom attribute applied to a module. Parameters specify the module, and the type of the ...
bool TryGetValue(TKey key, out TValue value)
Gets the value associated with the specified key.
virtual bool IsDefaultAttribute()
When overridden in a derived class, indicates whether the value of this instance is the default value...
static Attribute GetCustomAttribute(MemberInfo element, Type attributeType)
Retrieves a custom attribute applied to a member of a type. Parameters specify the member,...
The exception that is thrown when a requested method or operation is not implemented.
static Attribute [] GetCustomAttributes(MemberInfo element, Type type, bool inherit)
Retrieves an array of the custom attributes applied to a member of a type. Parameters specify the mem...
static Attribute [] GetCustomAttributes(MemberInfo element, bool inherit)
Retrieves an array of the custom attributes applied to a member of a type. Parameters specify the mem...