MethodInfo.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller
  23. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  24. public static bool operator ==(MethodInfo left, MethodInfo right)
  25. {
  26. // Test "right" first to allow branch elimination when inlined for null checks (== null)
  27. // so it can become a simple test
  28. if (right is null)
  29. {
  30. // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
  31. return (left is null) ? true : false;
  32. }
  33. // Quick reference equality test prior to calling the virtual Equality
  34. return ReferenceEquals(right, left) ? true : right.Equals(left);
  35. }
  36. public static bool operator !=(MethodInfo left, MethodInfo right) => !(left == right);
  37. }
  38. }