New test.
[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 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System.Diagnostics;
31 using System.Globalization;
32 using System.Reflection.Emit;
33 using System.Runtime.CompilerServices;
34 using System.Runtime.InteropServices;
35
36 namespace System.Reflection {
37
38 #if NET_2_0
39         [ComVisible (true)]
40         [ComDefaultInterfaceAttribute (typeof (_MethodBase))]
41 #endif
42         [Serializable]
43         [ClassInterface(ClassInterfaceType.None)]
44         public abstract class MethodBase: MemberInfo, _MethodBase {
45
46                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
47                 public extern static MethodBase GetCurrentMethod ();
48
49                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
50                 private extern static MethodBase GetMethodFromHandleInternal(IntPtr handle);
51
52                 public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle) {
53                         return GetMethodFromHandleInternal (handle.Value);
54                 }
55
56                 public abstract MethodImplAttributes GetMethodImplementationFlags();
57
58                 public abstract ParameterInfo[] GetParameters();
59                 
60                 //
61                 // This is a quick version for our own use. We should override
62                 // it where possible so that it does not allocate an array.
63                 //
64                 internal virtual int GetParameterCount ()
65                 {
66                         ParameterInfo [] pi = GetParameters ();
67                         if (pi == null)
68                                 return 0;
69                         
70                         return pi.Length;
71                 }
72
73 #if ONLY_1_1
74                 public new Type GetType ()
75                 {
76                         return base.GetType ();
77                 }
78 #endif
79
80                 [DebuggerHidden]
81                 [DebuggerStepThrough]           
82 #if NET_2_0 || BOOTSTRAP_NET_2_0
83                 virtual
84 #endif
85                 public Object Invoke(Object obj, Object[] parameters) {
86                         return Invoke (obj, 0, null, parameters, null);
87                 }
88
89                 public abstract Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture);
90
91                 protected MethodBase()
92                 {
93                 }
94
95                 public abstract RuntimeMethodHandle MethodHandle { get; }
96                 public abstract MethodAttributes Attributes { get; }
97                 public virtual CallingConventions CallingConvention { get {return CallingConventions.Standard;} }
98                 public Boolean IsPublic { 
99                         get {
100                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
101                         }
102                 }
103                 public Boolean IsPrivate {
104                         get {
105                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
106                         }
107                 }
108                 public Boolean IsFamily {
109                         get {
110                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family;
111                         }
112                 }
113                 public Boolean IsAssembly {
114                         get {
115                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly;
116                         }
117                 }
118                 public Boolean IsFamilyAndAssembly {
119                         get {
120                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem;
121                         }
122                 }
123                 public Boolean IsFamilyOrAssembly {
124                         get {
125                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem;
126                         }
127                 }
128                 public Boolean IsStatic {
129                         get {
130                                 return (Attributes & MethodAttributes.Static) != 0;
131                         }
132                 }
133                 public Boolean IsFinal {
134                         get {
135                                 return (Attributes & MethodAttributes.Final) != 0;
136                         }
137                 }
138                 public Boolean IsVirtual {
139                         get {
140                                 return (Attributes & MethodAttributes.Virtual) != 0;
141                         }
142                 }
143                 public Boolean IsHideBySig {
144                         get {
145                                 return (Attributes & MethodAttributes.HideBySig) != 0;
146                         }
147                 }
148                 public Boolean IsAbstract {
149                         get {
150                                 return (Attributes & MethodAttributes.Abstract) != 0;
151                         }
152                 }
153                 public Boolean IsSpecialName {
154                         get {
155                                 int attr = (int)Attributes;
156                                 return (attr & (int)MethodAttributes.SpecialName) != 0;
157                         }
158                 }
159                 public Boolean IsConstructor {
160                         get {
161                                 int attr = (int)Attributes;
162                                 return ((attr & (int)MethodAttributes.RTSpecialName) != 0
163                                         && (Name == ".ctor"));
164                         }
165                 }
166
167                 internal virtual int get_next_table_index (object obj, int table, bool inc) {
168                         if (this is MethodBuilder) {
169                                 MethodBuilder mb = (MethodBuilder)this;
170                                 return mb.get_next_table_index (obj, table, inc);
171                         }
172                         if (this is ConstructorBuilder) {
173                                 ConstructorBuilder mb = (ConstructorBuilder)this;
174                                 return mb.get_next_table_index (obj, table, inc);
175                         }
176                         throw new Exception ("Method is not a builder method");
177                 }
178
179 #if NET_2_0 || BOOTSTRAP_NET_2_0
180                 public virtual Type [] GetGenericArguments ()
181                 {
182                         throw new NotSupportedException ();
183                 }
184
185                 public virtual bool ContainsGenericParameters {
186                         get {
187                                 return false;
188                         }
189                 }
190
191                 public virtual bool IsGenericMethodDefinition {
192                         get {
193                                 throw new NotSupportedException ();
194                         }
195                 }
196
197                 public virtual bool IsGenericMethod {
198                         get {
199                                 throw new NotSupportedException ();
200                         }
201                 }
202 #endif
203
204 #if NET_2_0
205                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
206                 internal extern static MethodBody GetMethodBodyInternal (IntPtr handle);
207
208                 internal static MethodBody GetMethodBody (IntPtr handle) {
209                         return GetMethodBodyInternal (handle);
210                 }
211
212                 public virtual MethodBody GetMethodBody () {
213                         throw new NotSupportedException ();
214                 }
215 #endif
216
217                 void _MethodBase.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
218                 {
219                         throw new NotImplementedException ();
220                 }
221
222                 void _MethodBase.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
223                 {
224                         throw new NotImplementedException ();
225                 }
226
227                 void _MethodBase.GetTypeInfoCount (out uint pcTInfo)
228                 {
229                         throw new NotImplementedException ();
230                 }
231
232                 void _MethodBase.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
233                 {
234                         throw new NotImplementedException ();
235                 }
236         }
237 }