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 {
43 [ClassInterface(ClassInterfaceType.AutoDual)]
44 public abstract class MethodBase: MemberInfo {
46 [MethodImplAttribute (MethodImplOptions.InternalCall)]
47 public extern static MethodBase GetCurrentMethod ();
49 public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle)
54 public abstract MethodImplAttributes GetMethodImplementationFlags();
56 public abstract ParameterInfo[] GetParameters();
59 // This is a quick version for our own use. We should override
60 // it where possible so that it does not allocate an array.
62 internal virtual int GetParameterCount ()
64 ParameterInfo [] pi = GetParameters ();
73 #if NET_2_0 || BOOTSTRAP_NET_2_0
76 public Object Invoke(Object obj, Object[] parameters) {
77 return Invoke (obj, 0, null, parameters, null);
80 public abstract Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture);
82 protected MethodBase()
86 public abstract RuntimeMethodHandle MethodHandle { get; }
87 public abstract MethodAttributes Attributes { get; }
88 public virtual CallingConventions CallingConvention { get {return CallingConventions.Standard;} }
89 public Boolean IsPublic {
91 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
94 public Boolean IsPrivate {
96 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
99 public Boolean IsFamily {
101 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family;
104 public Boolean IsAssembly {
106 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly;
109 public Boolean IsFamilyAndAssembly {
111 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem;
114 public Boolean IsFamilyOrAssembly {
116 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem;
119 public Boolean IsStatic {
121 return (Attributes & MethodAttributes.Static) != 0;
124 public Boolean IsFinal {
126 return (Attributes & MethodAttributes.Final) != 0;
129 public Boolean IsVirtual {
131 return (Attributes & MethodAttributes.Virtual) != 0;
134 public Boolean IsHideBySig {
136 return (Attributes & MethodAttributes.HideBySig) != 0;
139 public Boolean IsAbstract {
141 return (Attributes & MethodAttributes.Abstract) != 0;
144 public Boolean IsSpecialName {
146 int attr = (int)Attributes;
147 return (attr & (int)MethodAttributes.SpecialName) != 0;
150 public Boolean IsConstructor {
152 int attr = (int)Attributes;
153 return ((attr & (int)MethodAttributes.RTSpecialName) != 0
154 && (Name == ".ctor"));
158 internal virtual int get_next_table_index (object obj, int table, bool inc) {
159 if (this is MethodBuilder) {
160 MethodBuilder mb = (MethodBuilder)this;
161 return mb.get_next_table_index (obj, table, inc);
163 if (this is ConstructorBuilder) {
164 ConstructorBuilder mb = (ConstructorBuilder)this;
165 return mb.get_next_table_index (obj, table, inc);
167 throw new Exception ("Method is not a builder method");
170 #if NET_2_0 || BOOTSTRAP_NET_2_0
171 public virtual MethodInfo BindGenericParameters (Type [] types)
173 throw new NotSupportedException ();
176 public virtual Type [] GetGenericArguments ()
178 throw new NotSupportedException ();
181 public virtual MethodInfo GetGenericMethodDefinition ()
183 throw new NotSupportedException ();
186 public virtual bool Mono_IsInflatedMethod {
188 throw new NotSupportedException ();
192 public virtual bool HasGenericParameters {
194 throw new NotSupportedException ();
198 public virtual bool IsGenericMethodDefinition {
200 throw new NotSupportedException ();