MethodInfo.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.
  4. using System.Runtime.CompilerServices;
  5. namespace System.Reflection
  6. {
  7. public abstract partial class MethodInfo : MethodBase
  8. {
  9. protected MethodInfo() { }
  10. public override MemberTypes MemberType => MemberTypes.Method;
  11. public virtual ParameterInfo ReturnParameter { get { throw NotImplemented.ByDesign; } }
  12. public virtual Type ReturnType { get { throw NotImplemented.ByDesign; } }
  13. public override Type[] GetGenericArguments() { throw new NotSupportedException(SR.NotSupported_SubclassOverride); }
  14. public virtual MethodInfo GetGenericMethodDefinition() { throw new NotSupportedException(SR.NotSupported_SubclassOverride); }
  15. public virtual MethodInfo MakeGenericMethod(params Type[] typeArguments) { throw new NotSupportedException(SR.NotSupported_SubclassOverride); }
  16. public abstract MethodInfo GetBaseDefinition();
  17. public abstract ICustomAttributeProvider ReturnTypeCustomAttributes { get; }
  18. public virtual Delegate CreateDelegate(Type delegateType) { throw new NotSupportedException(SR.NotSupported_SubclassOverride); }
  19. public virtual Delegate CreateDelegate(Type delegateType, object target) { throw new NotSupportedException(SR.NotSupported_SubclassOverride); }
  20. public override bool Equals(object obj) => base.Equals(obj);
  21. public override int GetHashCode() => base.GetHashCode();
  22. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  23. public static bool operator ==(MethodInfo left, MethodInfo right)
  24. {
  25. // Test "right" first to allow branch elimination when inlined for null checks (== null)
  26. // so it can become a simple test
  27. if (right is null)
  28. {
  29. // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
  30. return (left is null) ? true : false;
  31. }
  32. // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
  33. if ((object)left == (object)right)
  34. {
  35. return true;
  36. }
  37. return (left is null) ? false : left.Equals(right);
  38. }
  39. public static bool operator !=(MethodInfo left, MethodInfo right) => !(left == right);
  40. }
  41. }