1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 using System.Collections.Generic;
7 namespace System.Reflection
9 public abstract partial class MemberInfo : ICustomAttributeProvider
11 protected MemberInfo() { }
13 public abstract MemberTypes MemberType { get; }
14 public abstract string Name { get; }
15 public abstract Type DeclaringType { get; }
16 public abstract Type ReflectedType { get; }
18 public virtual Module Module
22 // This check is necessary because for some reason, Type adds a new "Module" property that hides the inherited one instead
25 Type type = this as Type;
29 throw NotImplemented.ByDesign;
33 public virtual bool HasSameMetadataDefinitionAs(MemberInfo other) { throw NotImplemented.ByDesign; }
35 public abstract bool IsDefined(Type attributeType, bool inherit);
36 public abstract object[] GetCustomAttributes(bool inherit);
37 public abstract object[] GetCustomAttributes(Type attributeType, bool inherit);
39 public virtual IEnumerable<CustomAttributeData> CustomAttributes => GetCustomAttributesData();
40 public virtual IList<CustomAttributeData> GetCustomAttributesData() { throw NotImplemented.ByDesign; }
41 public virtual bool IsCollectible => true;
42 public virtual int MetadataToken { get { throw new InvalidOperationException(); } }
44 public override bool Equals(object obj) => base.Equals(obj);
45 public override int GetHashCode() => base.GetHashCode();
47 public static bool operator ==(MemberInfo left, MemberInfo right)
49 if (object.ReferenceEquals(left, right))
52 if ((object)left == null || (object)right == null)
56 MethodBase method1, method2;
57 FieldInfo field1, field2;
58 EventInfo event1, event2;
59 PropertyInfo property1, property2;
61 if ((type1 = left as Type) != null && (type2 = right as Type) != null)
62 return type1 == type2;
63 else if ((method1 = left as MethodBase) != null && (method2 = right as MethodBase) != null)
64 return method1 == method2;
65 else if ((field1 = left as FieldInfo) != null && (field2 = right as FieldInfo) != null)
66 return field1 == field2;
67 else if ((event1 = left as EventInfo) != null && (event2 = right as EventInfo) != null)
68 return event1 == event2;
69 else if ((property1 = left as PropertyInfo) != null && (property2 = right as PropertyInfo) != null)
70 return property1 == property2;
75 public static bool operator !=(MemberInfo left, MemberInfo right) => !(left == right);