mscorlib(4.0.0.0) API with additions
Attribute.cs
2 using System.Reflection;
4 using System.Security;
5 
6 namespace System
7 {
10  [AttributeUsage(AttributeTargets.All, Inherited = true, AllowMultiple = false)]
11  [ClassInterface(ClassInterfaceType.None)]
12  [ComDefaultInterface(typeof(_Attribute))]
13  [ComVisible(true)]
14  [__DynamicallyInvokable]
15  public abstract class Attribute : _Attribute
16  {
19  public virtual object TypeId => GetType();
20 
21  private static Attribute[] InternalGetCustomAttributes(PropertyInfo element, Type type, bool inherit)
22  {
23  Attribute[] array = (Attribute[])element.GetCustomAttributes(type, inherit);
24  if (!inherit)
25  {
26  return array;
27  }
29  List<Attribute> list = new List<Attribute>();
30  CopyToArrayList(list, array, types);
31  Type[] indexParameterTypes = GetIndexParameterTypes(element);
32  PropertyInfo parentDefinition = GetParentDefinition(element, indexParameterTypes);
33  while (parentDefinition != null)
34  {
35  array = GetCustomAttributes(parentDefinition, type, inherit: false);
36  AddAttributesToList(list, array, types);
37  parentDefinition = GetParentDefinition(parentDefinition, indexParameterTypes);
38  }
39  Array array2 = CreateAttributeArrayHelper(type, list.Count);
40  Array.Copy(list.ToArray(), 0, array2, 0, list.Count);
41  return (Attribute[])array2;
42  }
43 
44  private static bool InternalIsDefined(PropertyInfo element, Type attributeType, bool inherit)
45  {
46  if (element.IsDefined(attributeType, inherit))
47  {
48  return true;
49  }
50  if (inherit)
51  {
52  AttributeUsageAttribute attributeUsageAttribute = InternalGetAttributeUsage(attributeType);
53  if (!attributeUsageAttribute.Inherited)
54  {
55  return false;
56  }
57  Type[] indexParameterTypes = GetIndexParameterTypes(element);
58  PropertyInfo parentDefinition = GetParentDefinition(element, indexParameterTypes);
59  while (parentDefinition != null)
60  {
61  if (parentDefinition.IsDefined(attributeType, inherit: false))
62  {
63  return true;
64  }
65  parentDefinition = GetParentDefinition(parentDefinition, indexParameterTypes);
66  }
67  }
68  return false;
69  }
70 
71  private static PropertyInfo GetParentDefinition(PropertyInfo property, Type[] propertyParameters)
72  {
73  MethodInfo methodInfo = property.GetGetMethod(nonPublic: true);
74  if (methodInfo == null)
75  {
76  methodInfo = property.GetSetMethod(nonPublic: true);
77  }
78  RuntimeMethodInfo runtimeMethodInfo = methodInfo as RuntimeMethodInfo;
79  if (runtimeMethodInfo != null)
80  {
81  runtimeMethodInfo = runtimeMethodInfo.GetParentDefinition();
82  if (runtimeMethodInfo != null)
83  {
84  return runtimeMethodInfo.DeclaringType.GetProperty(property.Name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, property.PropertyType, propertyParameters, null);
85  }
86  }
87  return null;
88  }
89 
90  private static Attribute[] InternalGetCustomAttributes(EventInfo element, Type type, bool inherit)
91  {
92  Attribute[] array = (Attribute[])element.GetCustomAttributes(type, inherit);
93  if (inherit)
94  {
96  List<Attribute> list = new List<Attribute>();
97  CopyToArrayList(list, array, types);
98  EventInfo parentDefinition = GetParentDefinition(element);
99  while (parentDefinition != null)
100  {
101  array = GetCustomAttributes(parentDefinition, type, inherit: false);
102  AddAttributesToList(list, array, types);
103  parentDefinition = GetParentDefinition(parentDefinition);
104  }
105  Array array2 = CreateAttributeArrayHelper(type, list.Count);
106  Array.Copy(list.ToArray(), 0, array2, 0, list.Count);
107  return (Attribute[])array2;
108  }
109  return array;
110  }
111 
112  private static EventInfo GetParentDefinition(EventInfo ev)
113  {
114  MethodInfo addMethod = ev.GetAddMethod(nonPublic: true);
115  RuntimeMethodInfo runtimeMethodInfo = addMethod as RuntimeMethodInfo;
116  if (runtimeMethodInfo != null)
117  {
118  runtimeMethodInfo = runtimeMethodInfo.GetParentDefinition();
119  if (runtimeMethodInfo != null)
120  {
121  return runtimeMethodInfo.DeclaringType.GetEvent(ev.Name);
122  }
123  }
124  return null;
125  }
126 
127  private static bool InternalIsDefined(EventInfo element, Type attributeType, bool inherit)
128  {
129  if (element.IsDefined(attributeType, inherit))
130  {
131  return true;
132  }
133  if (inherit)
134  {
135  AttributeUsageAttribute attributeUsageAttribute = InternalGetAttributeUsage(attributeType);
136  if (!attributeUsageAttribute.Inherited)
137  {
138  return false;
139  }
140  EventInfo parentDefinition = GetParentDefinition(element);
141  while (parentDefinition != null)
142  {
143  if (parentDefinition.IsDefined(attributeType, inherit: false))
144  {
145  return true;
146  }
147  parentDefinition = GetParentDefinition(parentDefinition);
148  }
149  }
150  return false;
151  }
152 
153  private static ParameterInfo GetParentDefinition(ParameterInfo param)
154  {
155  RuntimeMethodInfo runtimeMethodInfo = param.Member as RuntimeMethodInfo;
156  if (runtimeMethodInfo != null)
157  {
158  runtimeMethodInfo = runtimeMethodInfo.GetParentDefinition();
159  if (runtimeMethodInfo != null)
160  {
161  ParameterInfo[] parameters = runtimeMethodInfo.GetParameters();
162  return parameters[param.Position];
163  }
164  }
165  return null;
166  }
167 
168  private static Attribute[] InternalParamGetCustomAttributes(ParameterInfo param, Type type, bool inherit)
169  {
170  List<Type> list = new List<Type>();
171  if (type == null)
172  {
173  type = typeof(Attribute);
174  }
175  object[] customAttributes = param.GetCustomAttributes(type, inherit: false);
176  for (int i = 0; i < customAttributes.Length; i++)
177  {
178  Type type2 = customAttributes[i].GetType();
179  AttributeUsageAttribute attributeUsageAttribute = InternalGetAttributeUsage(type2);
180  if (!attributeUsageAttribute.AllowMultiple)
181  {
182  list.Add(type2);
183  }
184  }
185  Attribute[] array = null;
186  array = ((customAttributes.Length != 0) ? ((Attribute[])customAttributes) : CreateAttributeArrayHelper(type, 0));
187  if (param.Member.DeclaringType == null)
188  {
189  return array;
190  }
191  if (!inherit)
192  {
193  return array;
194  }
195  for (ParameterInfo parentDefinition = GetParentDefinition(param); parentDefinition != null; parentDefinition = GetParentDefinition(parentDefinition))
196  {
197  customAttributes = parentDefinition.GetCustomAttributes(type, inherit: false);
198  int num = 0;
199  for (int j = 0; j < customAttributes.Length; j++)
200  {
201  Type type3 = customAttributes[j].GetType();
202  AttributeUsageAttribute attributeUsageAttribute2 = InternalGetAttributeUsage(type3);
203  if (attributeUsageAttribute2.Inherited && !list.Contains(type3))
204  {
205  if (!attributeUsageAttribute2.AllowMultiple)
206  {
207  list.Add(type3);
208  }
209  num++;
210  }
211  else
212  {
213  customAttributes[j] = null;
214  }
215  }
216  Attribute[] array2 = CreateAttributeArrayHelper(type, num);
217  num = 0;
218  for (int k = 0; k < customAttributes.Length; k++)
219  {
220  if (customAttributes[k] != null)
221  {
222  array2[num] = (Attribute)customAttributes[k];
223  num++;
224  }
225  }
226  Attribute[] array3 = array;
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++)
231  {
232  array[num2 + l] = array2[l];
233  }
234  }
235  return array;
236  }
237 
238  private static bool InternalParamIsDefined(ParameterInfo param, Type type, bool inherit)
239  {
240  if (param.IsDefined(type, inherit: false))
241  {
242  return true;
243  }
244  if (param.Member.DeclaringType == null || !inherit)
245  {
246  return false;
247  }
248  for (ParameterInfo parentDefinition = GetParentDefinition(param); parentDefinition != null; parentDefinition = GetParentDefinition(parentDefinition))
249  {
250  object[] customAttributes = parentDefinition.GetCustomAttributes(type, inherit: false);
251  for (int i = 0; i < customAttributes.Length; i++)
252  {
253  Type type2 = customAttributes[i].GetType();
254  AttributeUsageAttribute attributeUsageAttribute = InternalGetAttributeUsage(type2);
255  if (customAttributes[i] is Attribute && attributeUsageAttribute.Inherited)
256  {
257  return true;
258  }
259  }
260  }
261  return false;
262  }
263 
264  private static void CopyToArrayList(List<Attribute> attributeList, Attribute[] attributes, Dictionary<Type, AttributeUsageAttribute> types)
265  {
266  for (int i = 0; i < attributes.Length; i++)
267  {
268  attributeList.Add(attributes[i]);
269  Type type = attributes[i].GetType();
270  if (!types.ContainsKey(type))
271  {
272  types[type] = InternalGetAttributeUsage(type);
273  }
274  }
275  }
276 
277  private static Type[] GetIndexParameterTypes(PropertyInfo element)
278  {
279  ParameterInfo[] indexParameters = element.GetIndexParameters();
280  if (indexParameters.Length != 0)
281  {
282  Type[] array = new Type[indexParameters.Length];
283  for (int i = 0; i < indexParameters.Length; i++)
284  {
285  array[i] = indexParameters[i].ParameterType;
286  }
287  return array;
288  }
289  return Array.Empty<Type>();
290  }
291 
292  private static void AddAttributesToList(List<Attribute> attributeList, Attribute[] attributes, Dictionary<Type, AttributeUsageAttribute> types)
293  {
294  for (int i = 0; i < attributes.Length; i++)
295  {
296  Type type = attributes[i].GetType();
297  AttributeUsageAttribute value = null;
298  types.TryGetValue(type, out value);
299  if (value == null)
300  {
301  value = (types[type] = InternalGetAttributeUsage(type));
302  if (value.Inherited)
303  {
304  attributeList.Add(attributes[i]);
305  }
306  }
307  else if (value.Inherited && value.AllowMultiple)
308  {
309  attributeList.Add(attributes[i]);
310  }
311  }
312  }
313 
314  private static AttributeUsageAttribute InternalGetAttributeUsage(Type type)
315  {
316  object[] customAttributes = type.GetCustomAttributes(typeof(AttributeUsageAttribute), inherit: false);
317  if (customAttributes.Length == 1)
318  {
319  return (AttributeUsageAttribute)customAttributes[0];
320  }
321  if (customAttributes.Length == 0)
322  {
323  return AttributeUsageAttribute.Default;
324  }
325  throw new FormatException(Environment.GetResourceString("Format_AttributeUsage", type));
326  }
327 
328  [SecuritySafeCritical]
329  private static Attribute[] CreateAttributeArrayHelper(Type elementType, int elementCount)
330  {
331  return (Attribute[])Array.UnsafeCreateInstance(elementType, elementCount);
332  }
333 
345  [__DynamicallyInvokable]
346  public static Attribute[] GetCustomAttributes(MemberInfo element, Type type)
347  {
348  return GetCustomAttributes(element, type, inherit: true);
349  }
350 
363  [__DynamicallyInvokable]
364  public static Attribute[] GetCustomAttributes(MemberInfo element, Type type, bool inherit)
365  {
366  if (element == null)
367  {
368  throw new ArgumentNullException("element");
369  }
370  if (type == null)
371  {
372  throw new ArgumentNullException("type");
373  }
374  if (!type.IsSubclassOf(typeof(Attribute)) && type != typeof(Attribute))
375  {
376  throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass"));
377  }
378  switch (element.MemberType)
379  {
380  case MemberTypes.Property:
381  return InternalGetCustomAttributes((PropertyInfo)element, type, inherit);
382  case MemberTypes.Event:
383  return InternalGetCustomAttributes((EventInfo)element, type, inherit);
384  default:
385  return element.GetCustomAttributes(type, inherit) as Attribute[];
386  }
387  }
388 
397  [__DynamicallyInvokable]
398  public static Attribute[] GetCustomAttributes(MemberInfo element)
399  {
400  return GetCustomAttributes(element, inherit: true);
401  }
402 
412  [__DynamicallyInvokable]
413  public static Attribute[] GetCustomAttributes(MemberInfo element, bool inherit)
414  {
415  if (element == null)
416  {
417  throw new ArgumentNullException("element");
418  }
419  switch (element.MemberType)
420  {
421  case MemberTypes.Property:
422  return InternalGetCustomAttributes((PropertyInfo)element, typeof(Attribute), inherit);
423  case MemberTypes.Event:
424  return InternalGetCustomAttributes((EventInfo)element, typeof(Attribute), inherit);
425  default:
426  return element.GetCustomAttributes(typeof(Attribute), inherit) as Attribute[];
427  }
428  }
429 
441  [__DynamicallyInvokable]
442  public static bool IsDefined(MemberInfo element, Type attributeType)
443  {
444  return IsDefined(element, attributeType, inherit: true);
445  }
446 
459  [__DynamicallyInvokable]
460  public static bool IsDefined(MemberInfo element, Type attributeType, bool inherit)
461  {
462  if (element == null)
463  {
464  throw new ArgumentNullException("element");
465  }
466  if (attributeType == null)
467  {
468  throw new ArgumentNullException("attributeType");
469  }
470  if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
471  {
472  throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass"));
473  }
474  switch (element.MemberType)
475  {
476  case MemberTypes.Property:
477  return InternalIsDefined((PropertyInfo)element, attributeType, inherit);
478  case MemberTypes.Event:
479  return InternalIsDefined((EventInfo)element, attributeType, inherit);
480  default:
481  return element.IsDefined(attributeType, inherit);
482  }
483  }
484 
497  [__DynamicallyInvokable]
498  public static Attribute GetCustomAttribute(MemberInfo element, Type attributeType)
499  {
500  return GetCustomAttribute(element, attributeType, inherit: true);
501  }
502 
516  [__DynamicallyInvokable]
517  public static Attribute GetCustomAttribute(MemberInfo element, Type attributeType, bool inherit)
518  {
519  Attribute[] customAttributes = GetCustomAttributes(element, attributeType, inherit);
520  if (customAttributes == null || customAttributes.Length == 0)
521  {
522  return null;
523  }
524  if (customAttributes.Length == 1)
525  {
526  return customAttributes[0];
527  }
528  throw new AmbiguousMatchException(Environment.GetResourceString("RFLCT.AmbigCust"));
529  }
530 
537  [__DynamicallyInvokable]
538  public static Attribute[] GetCustomAttributes(ParameterInfo element)
539  {
540  return GetCustomAttributes(element, inherit: true);
541  }
542 
552  [__DynamicallyInvokable]
553  public static Attribute[] GetCustomAttributes(ParameterInfo element, Type attributeType)
554  {
555  return GetCustomAttributes(element, attributeType, inherit: true);
556  }
557 
568  [__DynamicallyInvokable]
569  public static Attribute[] GetCustomAttributes(ParameterInfo element, Type attributeType, bool inherit)
570  {
571  if (element == null)
572  {
573  throw new ArgumentNullException("element");
574  }
575  if (attributeType == null)
576  {
577  throw new ArgumentNullException("attributeType");
578  }
579  if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
580  {
581  throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass"));
582  }
583  if (element.Member == null)
584  {
585  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidParameterInfo"), "element");
586  }
587  MemberInfo member = element.Member;
588  if (member.MemberType == MemberTypes.Method && inherit)
589  {
590  return InternalParamGetCustomAttributes(element, attributeType, inherit);
591  }
592  return element.GetCustomAttributes(attributeType, inherit) as Attribute[];
593  }
594 
603  [__DynamicallyInvokable]
604  public static Attribute[] GetCustomAttributes(ParameterInfo element, bool inherit)
605  {
606  if (element == null)
607  {
608  throw new ArgumentNullException("element");
609  }
610  if (element.Member == null)
611  {
612  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidParameterInfo"), "element");
613  }
614  MemberInfo member = element.Member;
615  if (member.MemberType == MemberTypes.Method && inherit)
616  {
617  return InternalParamGetCustomAttributes(element, null, inherit);
618  }
619  return element.GetCustomAttributes(typeof(Attribute), inherit) as Attribute[];
620  }
621 
631  [__DynamicallyInvokable]
632  public static bool IsDefined(ParameterInfo element, Type attributeType)
633  {
634  return IsDefined(element, attributeType, inherit: true);
635  }
636 
649  [__DynamicallyInvokable]
650  public static bool IsDefined(ParameterInfo element, Type attributeType, bool inherit)
651  {
652  if (element == null)
653  {
654  throw new ArgumentNullException("element");
655  }
656  if (attributeType == null)
657  {
658  throw new ArgumentNullException("attributeType");
659  }
660  if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
661  {
662  throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass"));
663  }
664  MemberInfo member = element.Member;
665  switch (member.MemberType)
666  {
667  case MemberTypes.Method:
668  return InternalParamIsDefined(element, attributeType, inherit);
669  case MemberTypes.Constructor:
670  return element.IsDefined(attributeType, inherit: false);
671  case MemberTypes.Property:
672  return element.IsDefined(attributeType, inherit: false);
673  default:
674  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidParamInfo"));
675  }
676  }
677 
688  [__DynamicallyInvokable]
689  public static Attribute GetCustomAttribute(ParameterInfo element, Type attributeType)
690  {
691  return GetCustomAttribute(element, attributeType, inherit: true);
692  }
693 
705  [__DynamicallyInvokable]
706  public static Attribute GetCustomAttribute(ParameterInfo element, Type attributeType, bool inherit)
707  {
708  Attribute[] customAttributes = GetCustomAttributes(element, attributeType, inherit);
709  if (customAttributes == null || customAttributes.Length == 0)
710  {
711  return null;
712  }
713  if (customAttributes.Length == 0)
714  {
715  return null;
716  }
717  if (customAttributes.Length == 1)
718  {
719  return customAttributes[0];
720  }
721  throw new AmbiguousMatchException(Environment.GetResourceString("RFLCT.AmbigCust"));
722  }
723 
732  public static Attribute[] GetCustomAttributes(Module element, Type attributeType)
733  {
734  return GetCustomAttributes(element, attributeType, inherit: true);
735  }
736 
742  public static Attribute[] GetCustomAttributes(Module element)
743  {
744  return GetCustomAttributes(element, inherit: true);
745  }
746 
753  public static Attribute[] GetCustomAttributes(Module element, bool inherit)
754  {
755  if (element == null)
756  {
757  throw new ArgumentNullException("element");
758  }
759  return (Attribute[])element.GetCustomAttributes(typeof(Attribute), inherit);
760  }
761 
771  public static Attribute[] GetCustomAttributes(Module element, Type attributeType, bool inherit)
772  {
773  if (element == null)
774  {
775  throw new ArgumentNullException("element");
776  }
777  if (attributeType == null)
778  {
779  throw new ArgumentNullException("attributeType");
780  }
781  if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
782  {
783  throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass"));
784  }
785  return (Attribute[])element.GetCustomAttributes(attributeType, inherit);
786  }
787 
797  public static bool IsDefined(Module element, Type attributeType)
798  {
799  return IsDefined(element, attributeType, inherit: false);
800  }
801 
812  public static bool IsDefined(Module element, Type attributeType, bool inherit)
813  {
814  if (element == null)
815  {
816  throw new ArgumentNullException("element");
817  }
818  if (attributeType == null)
819  {
820  throw new ArgumentNullException("attributeType");
821  }
822  if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
823  {
824  throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass"));
825  }
826  return element.IsDefined(attributeType, inherit: false);
827  }
828 
838  public static Attribute GetCustomAttribute(Module element, Type attributeType)
839  {
840  return GetCustomAttribute(element, attributeType, inherit: true);
841  }
842 
853  public static Attribute GetCustomAttribute(Module element, Type attributeType, bool inherit)
854  {
855  Attribute[] customAttributes = GetCustomAttributes(element, attributeType, inherit);
856  if (customAttributes == null || customAttributes.Length == 0)
857  {
858  return null;
859  }
860  if (customAttributes.Length == 1)
861  {
862  return customAttributes[0];
863  }
864  throw new AmbiguousMatchException(Environment.GetResourceString("RFLCT.AmbigCust"));
865  }
866 
875  [__DynamicallyInvokable]
876  public static Attribute[] GetCustomAttributes(Assembly element, Type attributeType)
877  {
878  return GetCustomAttributes(element, attributeType, inherit: true);
879  }
880 
890  public static Attribute[] GetCustomAttributes(Assembly element, Type attributeType, bool inherit)
891  {
892  if (element == null)
893  {
894  throw new ArgumentNullException("element");
895  }
896  if (attributeType == null)
897  {
898  throw new ArgumentNullException("attributeType");
899  }
900  if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
901  {
902  throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass"));
903  }
904  return (Attribute[])element.GetCustomAttributes(attributeType, inherit);
905  }
906 
912  [__DynamicallyInvokable]
913  public static Attribute[] GetCustomAttributes(Assembly element)
914  {
915  return GetCustomAttributes(element, inherit: true);
916  }
917 
924  public static Attribute[] GetCustomAttributes(Assembly element, bool inherit)
925  {
926  if (element == null)
927  {
928  throw new ArgumentNullException("element");
929  }
930  return (Attribute[])element.GetCustomAttributes(typeof(Attribute), inherit);
931  }
932 
942  [__DynamicallyInvokable]
943  public static bool IsDefined(Assembly element, Type attributeType)
944  {
945  return IsDefined(element, attributeType, inherit: true);
946  }
947 
958  public static bool IsDefined(Assembly element, Type attributeType, bool inherit)
959  {
960  if (element == null)
961  {
962  throw new ArgumentNullException("element");
963  }
964  if (attributeType == null)
965  {
966  throw new ArgumentNullException("attributeType");
967  }
968  if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
969  {
970  throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass"));
971  }
972  return element.IsDefined(attributeType, inherit: false);
973  }
974 
984  [__DynamicallyInvokable]
985  public static Attribute GetCustomAttribute(Assembly element, Type attributeType)
986  {
987  return GetCustomAttribute(element, attributeType, inherit: true);
988  }
989 
1000  public static Attribute GetCustomAttribute(Assembly element, Type attributeType, bool inherit)
1001  {
1002  Attribute[] customAttributes = GetCustomAttributes(element, attributeType, inherit);
1003  if (customAttributes == null || customAttributes.Length == 0)
1004  {
1005  return null;
1006  }
1007  if (customAttributes.Length == 1)
1008  {
1009  return customAttributes[0];
1010  }
1011  throw new AmbiguousMatchException(Environment.GetResourceString("RFLCT.AmbigCust"));
1012  }
1013 
1015  [__DynamicallyInvokable]
1016  protected Attribute()
1017  {
1018  }
1019 
1024  [SecuritySafeCritical]
1025  [__DynamicallyInvokable]
1026  public override bool Equals(object obj)
1027  {
1028  if (obj == null)
1029  {
1030  return false;
1031  }
1032  RuntimeType runtimeType = (RuntimeType)GetType();
1033  RuntimeType left = (RuntimeType)obj.GetType();
1034  if (left != runtimeType)
1035  {
1036  return false;
1037  }
1038  FieldInfo[] fields = runtimeType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
1039  for (int i = 0; i < fields.Length; i++)
1040  {
1041  object thisValue = ((RtFieldInfo)fields[i]).UnsafeGetValue(this);
1042  object thatValue = ((RtFieldInfo)fields[i]).UnsafeGetValue(obj);
1043  if (!AreFieldValuesEqual(thisValue, thatValue))
1044  {
1045  return false;
1046  }
1047  }
1048  return true;
1049  }
1050 
1051  private static bool AreFieldValuesEqual(object thisValue, object thatValue)
1052  {
1053  if (thisValue == null && thatValue == null)
1054  {
1055  return true;
1056  }
1057  if (thisValue == null || thatValue == null)
1058  {
1059  return false;
1060  }
1061  if (thisValue.GetType().IsArray)
1062  {
1063  if (!thisValue.GetType().Equals(thatValue.GetType()))
1064  {
1065  return false;
1066  }
1067  Array array = thisValue as Array;
1068  Array array2 = thatValue as Array;
1069  if (array.Length != array2.Length)
1070  {
1071  return false;
1072  }
1073  for (int i = 0; i < array.Length; i++)
1074  {
1075  if (!AreFieldValuesEqual(array.GetValue(i), array2.GetValue(i)))
1076  {
1077  return false;
1078  }
1079  }
1080  }
1081  else if (!thisValue.Equals(thatValue))
1082  {
1083  return false;
1084  }
1085  return true;
1086  }
1087 
1090  [SecuritySafeCritical]
1091  [__DynamicallyInvokable]
1092  public override int GetHashCode()
1093  {
1094  Type type = GetType();
1095  FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
1096  object obj = null;
1097  for (int i = 0; i < fields.Length; i++)
1098  {
1099  object obj2 = ((RtFieldInfo)fields[i]).UnsafeGetValue(this);
1100  if (obj2 != null && !obj2.GetType().IsArray)
1101  {
1102  obj = obj2;
1103  }
1104  if (obj != null)
1105  {
1106  break;
1107  }
1108  }
1109  return obj?.GetHashCode() ?? type.GetHashCode();
1110  }
1111 
1116  public virtual bool Match(object obj)
1117  {
1118  return Equals(obj);
1119  }
1120 
1124  public virtual bool IsDefaultAttribute()
1125  {
1126  return false;
1127  }
1128 
1132  void _Attribute.GetTypeInfoCount(out uint pcTInfo)
1133  {
1134  throw new NotImplementedException();
1135  }
1136 
1142  void _Attribute.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
1143  {
1144  throw new NotImplementedException();
1145  }
1146 
1154  void _Attribute.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
1155  {
1156  throw new NotImplementedException();
1157  }
1158 
1169  void _Attribute.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
1170  {
1171  throw new NotImplementedException();
1172  }
1173  }
1174 }
Obtains information about the attributes of a member and provides access to member metadata.
Definition: MemberInfo.cs:14
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...
Definition: Attribute.cs:569
Performs reflection on a module.
Definition: Module.cs:17
FieldInfo [] GetFields()
Returns all the public fields of the current T:System.Type.
Definition: Type.cs:1695
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...
Definition: Attribute.cs:1116
virtual object [] GetCustomAttributes(bool inherit)
Returns all custom attributes.
Definition: Module.cs:218
static Attribute [] GetCustomAttributes(ParameterInfo element)
Retrieves an array of the custom attributes applied to a method parameter. A parameter specifies the ...
Definition: Attribute.cs:538
override int GetHashCode()
Returns the hash code for this instance.
Definition: Type.cs:2870
abstract Type DeclaringType
Gets the class that declares this member.
Definition: MemberInfo.cs:36
static bool IsDefined(Assembly element, Type attributeType)
Determines whether any custom attributes are applied to an assembly. Parameters specify the assembly,...
Definition: Attribute.cs:943
Discovers the attributes of a method and provides access to method metadata.
Definition: MethodInfo.cs:13
virtual bool IsDefined(Type attributeType, bool inherit)
Indicates whether or not a specified attribute has been applied to the assembly.
Definition: Assembly.cs:1070
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...
Definition: Attribute.cs:853
Represents the base class for custom attributes.
Definition: Attribute.cs:15
Discovers the attributes of a field and provides access to field metadata.
Definition: FieldInfo.cs:15
static Attribute [] GetCustomAttributes(MemberInfo element)
Retrieves an array of the custom attributes applied to a member of a type. A parameter specifies the ...
Definition: Attribute.cs:398
BindingFlags
Specifies flags that control binding and the way in which the search for members and types is conduct...
Definition: BindingFlags.cs:10
Definition: __Canon.cs:3
static Attribute [] GetCustomAttributes(Module element, Type attributeType)
Retrieves an array of the custom attributes applied to a module. Parameters specify the module,...
Definition: Attribute.cs:732
static Attribute [] GetCustomAttributes(Assembly element)
Retrieves an array of the custom attributes applied to an assembly. A parameter specifies the assembl...
Definition: Attribute.cs:913
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.
Definition: Attribute.cs:19
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...
Definition: Attribute.cs:460
static Attribute [] GetCustomAttributes(Assembly element, Type attributeType, bool inherit)
Retrieves an array of the custom attributes applied to an assembly. Parameters specify the assembly,...
Definition: Attribute.cs:890
static Attribute GetCustomAttribute(ParameterInfo element, Type attributeType, bool inherit)
Retrieves a custom attribute applied to a method parameter. Parameters specify the method parameter,...
Definition: Attribute.cs:706
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...
Definition: Attribute.cs:650
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.
Definition: Assembly.cs:1041
bool ContainsKey(TKey key)
Determines whether the T:System.Collections.Generic.Dictionary`2 contains the specified key.
Definition: Dictionary.cs:1303
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...
Definition: Type.cs:1827
Exposes the T:System.Attribute class to unmanaged code.
Definition: _Attribute.cs:9
virtual bool IsSubclassOf(Type c)
Determines whether the current T:System.Type derives from the specified T:System.Type.
Definition: Type.cs:2664
static Attribute GetCustomAttribute(MemberInfo element, Type attributeType, bool inherit)
Retrieves a custom attribute applied to a member of a type. Parameters specify the member,...
Definition: Attribute.cs:517
void Add(T item)
Adds an object to the end of the T:System.Collections.Generic.List`1.
Definition: List.cs:510
static bool IsDefined(Module element, Type attributeType, bool inherit)
Determines whether any custom attributes are applied to a module. Parameters specify the module,...
Definition: Attribute.cs:812
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
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,...
Definition: Attribute.cs:924
static Attribute [] GetCustomAttributes(Assembly element, Type attributeType)
Retrieves an array of the custom attributes applied to an assembly. Parameters specify the assembly,...
Definition: Attribute.cs:876
EventInfo GetEvent(string name)
Returns the T:System.Reflection.EventInfo object representing the specified public event.
Definition: Type.cs:1782
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...
Definition: Attribute.cs:632
static Attribute GetCustomAttribute(ParameterInfo element, Type attributeType)
Retrieves a custom attribute applied to a method parameter. Parameters specify the method parameter,...
Definition: Attribute.cs:689
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
Definition: Assembly.cs:22
static Attribute [] GetCustomAttributes(Module element, Type attributeType, bool inherit)
Retrieves an array of the custom attributes applied to a module. Parameters specify the module,...
Definition: Attribute.cs:771
Discovers the attributes of an event and provides access to event metadata.
Definition: EventInfo.cs:15
static Attribute [] GetCustomAttributes(Module element, bool inherit)
Retrieves an array of the custom attributes applied to a module. Parameters specify the module,...
Definition: Attribute.cs:753
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
Type DeclaringType
Provides COM objects with version-independent access to the P:System.Reflection.MemberInfo....
Definition: _MethodInfo.cs:31
static bool IsDefined(Module element, Type attributeType)
Determines whether any custom attributes of a specified type are applied to a module....
Definition: Attribute.cs:797
static bool IsDefined(Assembly element, Type attributeType, bool inherit)
Determines whether any custom attributes are applied to an assembly. Parameters specify the assembly,...
Definition: Attribute.cs:958
static Attribute [] GetCustomAttributes(Module element)
Retrieves an array of the custom attributes applied to a module. A parameter specifies the module.
Definition: Attribute.cs:742
abstract string Name
Gets the name of the current member.
Definition: MemberInfo.cs:27
abstract Type PropertyType
Gets the type of this property.
Definition: PropertyInfo.cs:25
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,...
Definition: Dictionary.cs:17
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.
Definition: PropertyInfo.cs:15
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...
Definition: Attribute.cs:346
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...
Definition: List.cs:14
static Attribute GetCustomAttribute(Assembly element, Type attributeType)
Retrieves a custom attribute applied to a specified assembly. Parameters specify the assembly and the...
Definition: Attribute.cs:985
static Attribute [] GetCustomAttributes(ParameterInfo element, bool inherit)
Retrieves an array of the custom attributes applied to a method parameter. Parameters specify the met...
Definition: Attribute.cs:604
static Attribute [] GetCustomAttributes(ParameterInfo element, Type attributeType)
Retrieves an array of the custom attributes applied to a method parameter. Parameters specify the met...
Definition: Attribute.cs:553
override int GetHashCode()
Returns the hash code for this instance.
Definition: Attribute.cs:1092
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 ...
Definition: MemberInfo.cs:19
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,...
Definition: Attribute.cs:1000
virtual bool IsDefined(Type attributeType, bool inherit)
Returns a value that indicates whether the specified attribute type has been applied to this module.
Definition: Module.cs:245
static bool IsDefined(MemberInfo element, Type attributeType)
Determines whether any custom attributes are applied to a member of a type. Parameters specify the me...
Definition: Attribute.cs:442
Attribute()
Initializes a new instance of the T:System.Attribute class.
Definition: Attribute.cs:1016
override bool Equals(object obj)
Returns a value that indicates whether this instance is equal to a specified object.
Definition: Attribute.cs:1026
MemberTypes
Marks each type of member that is defined as a derived class of T:System.Reflection....
Definition: MemberTypes.cs:9
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 ...
Definition: Attribute.cs:838
bool TryGetValue(TKey key, out TValue value)
Gets the value associated with the specified key.
Definition: Dictionary.cs:1624
virtual bool IsDefaultAttribute()
When overridden in a derived class, indicates whether the value of this instance is the default value...
Definition: Attribute.cs:1124
static Attribute GetCustomAttribute(MemberInfo element, Type attributeType)
Retrieves a custom attribute applied to a member of a type. Parameters specify the member,...
Definition: Attribute.cs:498
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...
Definition: Attribute.cs:364
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...
Definition: Attribute.cs:413