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
;
6 using System
.Runtime
.CompilerServices
;
8 namespace System
.Reflection
10 public abstract partial class MemberInfo
: ICustomAttributeProvider
12 protected MemberInfo() { }
14 public abstract MemberTypes MemberType { get; }
15 public abstract string Name { get; }
16 public abstract Type
? DeclaringType { get; }
17 public abstract Type
? ReflectedType { get; }
19 public virtual Module Module
23 // This check is necessary because for some reason, Type adds a new "Module" property that hides the inherited one instead
26 if (this is Type 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
=> throw new InvalidOperationException();
44 public override bool Equals(object? obj
) => base.Equals(obj
);
45 public override int GetHashCode() => base.GetHashCode();
47 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
48 public static bool operator ==(MemberInfo
? left
, MemberInfo
? right
)
50 // Test "right" first to allow branch elimination when inlined for null checks (== null)
51 // so it can become a simple test
54 // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
55 return (left
is null) ? true : false;
58 // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
59 if ((object?)left
== (object)right
)
64 return (left
is null) ? false : left
.Equals(right
);
67 public static bool operator !=(MemberInfo
? left
, MemberInfo
? right
) => !(left
== right
);