Switch to compiler-tester
[mono.git] / mcs / class / corlib / System.Reflection / MethodBase.cs
1 //
2 // System.Reflection/MethodBase.cs
3 //
4 // Author:
5 //   Paolo Molaro (lupus@ximian.com)
6 //
7 // (C) 2001 Ximian, Inc.  http://www.ximian.com
8 //
9
10 //
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 //
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:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
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.
31 //
32
33 using System;
34 using System.Diagnostics;
35 using System.Globalization;
36 using System.Reflection.Emit;
37 using System.Runtime.CompilerServices;
38 using System.Runtime.InteropServices;
39
40 namespace System.Reflection {
41
42 #if NET_2_0
43         [ComVisible (true)]
44         [ComDefaultInterfaceAttribute (typeof (_MethodBase))]
45 #endif
46         [Serializable]
47         [ClassInterface(ClassInterfaceType.None)]
48         public abstract class MethodBase: MemberInfo {
49
50                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
51                 public extern static MethodBase GetCurrentMethod ();
52
53                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
54                 private extern static MethodBase GetMethodFromHandleInternal(IntPtr handle);
55
56                 public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle) {
57                         return GetMethodFromHandleInternal (handle.Value);
58                 }
59
60                 public abstract MethodImplAttributes GetMethodImplementationFlags();
61
62                 public abstract ParameterInfo[] GetParameters();
63                 
64                 //
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.
67                 //
68                 internal virtual int GetParameterCount ()
69                 {
70                         ParameterInfo [] pi = GetParameters ();
71                         if (pi == null)
72                                 return 0;
73                         
74                         return pi.Length;
75                 }
76
77                 [DebuggerHidden]
78                 [DebuggerStepThrough]           
79 #if NET_2_0 || BOOTSTRAP_NET_2_0
80                 virtual
81 #endif
82                 public Object Invoke(Object obj, Object[] parameters) {
83                         return Invoke (obj, 0, null, parameters, null);
84                 }
85
86                 public abstract Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture);
87
88                 protected MethodBase()
89                 {
90                 }
91
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 { 
96                         get {
97                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
98                         }
99                 }
100                 public Boolean IsPrivate {
101                         get {
102                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
103                         }
104                 }
105                 public Boolean IsFamily {
106                         get {
107                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family;
108                         }
109                 }
110                 public Boolean IsAssembly {
111                         get {
112                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly;
113                         }
114                 }
115                 public Boolean IsFamilyAndAssembly {
116                         get {
117                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem;
118                         }
119                 }
120                 public Boolean IsFamilyOrAssembly {
121                         get {
122                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem;
123                         }
124                 }
125                 public Boolean IsStatic {
126                         get {
127                                 return (Attributes & MethodAttributes.Static) != 0;
128                         }
129                 }
130                 public Boolean IsFinal {
131                         get {
132                                 return (Attributes & MethodAttributes.Final) != 0;
133                         }
134                 }
135                 public Boolean IsVirtual {
136                         get {
137                                 return (Attributes & MethodAttributes.Virtual) != 0;
138                         }
139                 }
140                 public Boolean IsHideBySig {
141                         get {
142                                 return (Attributes & MethodAttributes.HideBySig) != 0;
143                         }
144                 }
145                 public Boolean IsAbstract {
146                         get {
147                                 return (Attributes & MethodAttributes.Abstract) != 0;
148                         }
149                 }
150                 public Boolean IsSpecialName {
151                         get {
152                                 int attr = (int)Attributes;
153                                 return (attr & (int)MethodAttributes.SpecialName) != 0;
154                         }
155                 }
156                 public Boolean IsConstructor {
157                         get {
158                                 int attr = (int)Attributes;
159                                 return ((attr & (int)MethodAttributes.RTSpecialName) != 0
160                                         && (Name == ".ctor"));
161                         }
162                 }
163
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);
168                         }
169                         if (this is ConstructorBuilder) {
170                                 ConstructorBuilder mb = (ConstructorBuilder)this;
171                                 return mb.get_next_table_index (obj, table, inc);
172                         }
173                         throw new Exception ("Method is not a builder method");
174                 }
175
176 #if NET_2_0 || BOOTSTRAP_NET_2_0
177                 public virtual MethodInfo BindGenericParameters (Type [] types)
178                 {
179                         throw new NotSupportedException ();
180                 }
181
182                 public virtual Type [] GetGenericArguments ()
183                 {
184                         throw new NotSupportedException ();
185                 }
186
187                 public virtual MethodInfo GetGenericMethodDefinition ()
188                 {
189                         throw new NotSupportedException ();
190                 }
191
192                 public virtual bool Mono_IsInflatedMethod {
193                         get {
194                                 throw new NotSupportedException ();
195                         }
196                 }
197
198                 public virtual bool HasGenericParameters {
199                         get {
200                                 throw new NotSupportedException ();
201                         }
202                 }
203
204                 public virtual bool IsGenericMethodDefinition {
205                         get {
206                                 throw new NotSupportedException ();
207                         }
208                 }
209 #endif
210
211 #if NET_2_0
212                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
213                 internal extern static MethodBody GetMethodBodyInternal (IntPtr handle);
214
215                 internal static MethodBody GetMethodBody (IntPtr handle) {
216                         MethodBody mb = GetMethodBodyInternal (handle);
217                         if (mb == null)
218                                 throw new ArgumentException ("Only methods with IL bodies are supported.");
219                         else
220                                 return mb;
221                 }                       
222
223                 public virtual MethodBody GetMethodBody () {
224                         throw new NotSupportedException ();
225                 }
226 #endif
227         }
228 }