2 // System.Reflection/MethodBase.cs
5 // Paolo Molaro (lupus@ximian.com)
7 // (C) 2001 Ximian, Inc. http://www.ximian.com
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Diagnostics;
35 using System.Globalization;
36 using System.Reflection.Emit;
37 using System.Runtime.CompilerServices;
38 using System.Runtime.InteropServices;
40 namespace System.Reflection {
44 [ComDefaultInterfaceAttribute (typeof (_MethodBase))]
47 [ClassInterface(ClassInterfaceType.None)]
48 public abstract class MethodBase: MemberInfo {
50 [MethodImplAttribute (MethodImplOptions.InternalCall)]
51 public extern static MethodBase GetCurrentMethod ();
53 [MethodImplAttribute (MethodImplOptions.InternalCall)]
54 private extern static MethodBase GetMethodFromHandleInternal(IntPtr handle);
56 public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle) {
57 return GetMethodFromHandleInternal (handle.Value);
60 public abstract MethodImplAttributes GetMethodImplementationFlags();
62 public abstract ParameterInfo[] GetParameters();
65 // This is a quick version for our own use. We should override
66 // it where possible so that it does not allocate an array.
68 internal virtual int GetParameterCount ()
70 ParameterInfo [] pi = GetParameters ();
79 #if NET_2_0 || BOOTSTRAP_NET_2_0
82 public Object Invoke(Object obj, Object[] parameters) {
83 return Invoke (obj, 0, null, parameters, null);
86 public abstract Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture);
88 protected MethodBase()
92 public abstract RuntimeMethodHandle MethodHandle { get; }
93 public abstract MethodAttributes Attributes { get; }
94 public virtual CallingConventions CallingConvention { get {return CallingConventions.Standard;} }
95 public Boolean IsPublic {
97 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
100 public Boolean IsPrivate {
102 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
105 public Boolean IsFamily {
107 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family;
110 public Boolean IsAssembly {
112 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly;
115 public Boolean IsFamilyAndAssembly {
117 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem;
120 public Boolean IsFamilyOrAssembly {
122 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem;
125 public Boolean IsStatic {
127 return (Attributes & MethodAttributes.Static) != 0;
130 public Boolean IsFinal {
132 return (Attributes & MethodAttributes.Final) != 0;
135 public Boolean IsVirtual {
137 return (Attributes & MethodAttributes.Virtual) != 0;
140 public Boolean IsHideBySig {
142 return (Attributes & MethodAttributes.HideBySig) != 0;
145 public Boolean IsAbstract {
147 return (Attributes & MethodAttributes.Abstract) != 0;
150 public Boolean IsSpecialName {
152 int attr = (int)Attributes;
153 return (attr & (int)MethodAttributes.SpecialName) != 0;
156 public Boolean IsConstructor {
158 int attr = (int)Attributes;
159 return ((attr & (int)MethodAttributes.RTSpecialName) != 0
160 && (Name == ".ctor"));
164 internal virtual int get_next_table_index (object obj, int table, bool inc) {
165 if (this is MethodBuilder) {
166 MethodBuilder mb = (MethodBuilder)this;
167 return mb.get_next_table_index (obj, table, inc);
169 if (this is ConstructorBuilder) {
170 ConstructorBuilder mb = (ConstructorBuilder)this;
171 return mb.get_next_table_index (obj, table, inc);
173 throw new Exception ("Method is not a builder method");
176 #if NET_2_0 || BOOTSTRAP_NET_2_0
177 public virtual MethodInfo BindGenericParameters (Type [] types)
179 throw new NotSupportedException ();
182 public virtual Type [] GetGenericArguments ()
184 throw new NotSupportedException ();
187 public virtual MethodInfo GetGenericMethodDefinition ()
189 throw new NotSupportedException ();
192 public virtual bool Mono_IsInflatedMethod {
194 throw new NotSupportedException ();
198 public virtual bool HasGenericParameters {
200 throw new NotSupportedException ();
204 public virtual bool IsGenericMethodDefinition {
206 throw new NotSupportedException ();
212 [MethodImplAttribute (MethodImplOptions.InternalCall)]
213 internal extern static MethodBody GetMethodBodyInternal (IntPtr handle);
215 internal static MethodBody GetMethodBody (IntPtr handle) {
216 MethodBody mb = GetMethodBodyInternal (handle);
218 throw new ArgumentException ("Only methods with IL bodies are supported.");
223 public virtual MethodBody GetMethodBody () {
224 throw new NotSupportedException ();