MethodBase.cs 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.Globalization;
  5. using System.Diagnostics;
  6. namespace System.Reflection
  7. {
  8. public abstract partial class MethodBase : MemberInfo
  9. {
  10. protected MethodBase() { }
  11. public abstract ParameterInfo[] GetParameters();
  12. public abstract MethodAttributes Attributes { get; }
  13. public virtual MethodImplAttributes MethodImplementationFlags => GetMethodImplementationFlags();
  14. public abstract MethodImplAttributes GetMethodImplementationFlags();
  15. public virtual MethodBody GetMethodBody() { throw new InvalidOperationException(); }
  16. public virtual CallingConventions CallingConvention => CallingConventions.Standard;
  17. public bool IsAbstract => (Attributes & MethodAttributes.Abstract) != 0;
  18. public bool IsConstructor
  19. {
  20. get
  21. {
  22. // To be backward compatible we only return true for instance RTSpecialName ctors.
  23. return (this is ConstructorInfo &&
  24. !IsStatic &&
  25. ((Attributes & MethodAttributes.RTSpecialName) == MethodAttributes.RTSpecialName));
  26. }
  27. }
  28. public bool IsFinal => (Attributes & MethodAttributes.Final) != 0;
  29. public bool IsHideBySig => (Attributes & MethodAttributes.HideBySig) != 0;
  30. public bool IsSpecialName => (Attributes & MethodAttributes.SpecialName) != 0;
  31. public bool IsStatic => (Attributes & MethodAttributes.Static) != 0;
  32. public bool IsVirtual => (Attributes & MethodAttributes.Virtual) != 0;
  33. public bool IsAssembly => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly;
  34. public bool IsFamily => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family;
  35. public bool IsFamilyAndAssembly => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem;
  36. public bool IsFamilyOrAssembly => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem;
  37. public bool IsPrivate => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
  38. public bool IsPublic => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
  39. public virtual bool IsConstructedGenericMethod => IsGenericMethod && !IsGenericMethodDefinition;
  40. public virtual bool IsGenericMethod => false;
  41. public virtual bool IsGenericMethodDefinition => false;
  42. public virtual Type[] GetGenericArguments() { throw new NotSupportedException(SR.NotSupported_SubclassOverride); }
  43. public virtual bool ContainsGenericParameters => false;
  44. [DebuggerHidden]
  45. [DebuggerStepThrough]
  46. public object Invoke(object obj, object[] parameters) => Invoke(obj, BindingFlags.Default, binder: null, parameters: parameters, culture: null);
  47. public abstract object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture);
  48. public abstract RuntimeMethodHandle MethodHandle { get; }
  49. public virtual bool IsSecurityCritical { get { throw NotImplemented.ByDesign; } }
  50. public virtual bool IsSecuritySafeCritical { get { throw NotImplemented.ByDesign; } }
  51. public virtual bool IsSecurityTransparent { get { throw NotImplemented.ByDesign; } }
  52. public override bool Equals(object obj) => base.Equals(obj);
  53. public override int GetHashCode() => base.GetHashCode();
  54. public static bool operator ==(MethodBase left, MethodBase right)
  55. {
  56. if (object.ReferenceEquals(left, right))
  57. return true;
  58. if ((object)left == null || (object)right == null)
  59. return false;
  60. MethodInfo method1, method2;
  61. ConstructorInfo constructor1, constructor2;
  62. if ((method1 = left as MethodInfo) != null && (method2 = right as MethodInfo) != null)
  63. return method1 == method2;
  64. else if ((constructor1 = left as ConstructorInfo) != null && (constructor2 = right as ConstructorInfo) != null)
  65. return constructor1 == constructor2;
  66. return false;
  67. }
  68. public static bool operator !=(MethodBase left, MethodBase right) => !(left == right);
  69. }
  70. }