2004-07-07 Sebastien Pouliot <sebastien@ximian.com>
[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         [Serializable]
43         [ClassInterface(ClassInterfaceType.AutoDual)]
44         public abstract class MethodBase: MemberInfo {
45
46                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
47                 public extern static MethodBase GetCurrentMethod ();
48
49                 public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle)
50                 {
51                         return null;
52                 }
53
54                 public abstract MethodImplAttributes GetMethodImplementationFlags();
55
56                 public abstract ParameterInfo[] GetParameters();
57                 
58                 //
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.
61                 //
62                 internal virtual int GetParameterCount ()
63                 {
64                         ParameterInfo [] pi = GetParameters ();
65                         if (pi == null)
66                                 return 0;
67                         
68                         return pi.Length;
69                 }
70
71                 [DebuggerHidden]
72                 [DebuggerStepThrough]           
73 #if NET_2_0 || BOOTSTRAP_NET_2_0
74                 virtual
75 #endif
76                 public Object Invoke(Object obj, Object[] parameters) {
77                         return Invoke (obj, 0, null, parameters, null);
78                 }
79
80                 public abstract Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture);
81
82                 protected MethodBase()
83                 {
84                 }
85
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 { 
90                         get {
91                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
92                         }
93                 }
94                 public Boolean IsPrivate {
95                         get {
96                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
97                         }
98                 }
99                 public Boolean IsFamily {
100                         get {
101                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family;
102                         }
103                 }
104                 public Boolean IsAssembly {
105                         get {
106                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly;
107                         }
108                 }
109                 public Boolean IsFamilyAndAssembly {
110                         get {
111                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem;
112                         }
113                 }
114                 public Boolean IsFamilyOrAssembly {
115                         get {
116                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem;
117                         }
118                 }
119                 public Boolean IsStatic {
120                         get {
121                                 return (Attributes & MethodAttributes.Static) != 0;
122                         }
123                 }
124                 public Boolean IsFinal {
125                         get {
126                                 return (Attributes & MethodAttributes.Final) != 0;
127                         }
128                 }
129                 public Boolean IsVirtual {
130                         get {
131                                 return (Attributes & MethodAttributes.Virtual) != 0;
132                         }
133                 }
134                 public Boolean IsHideBySig {
135                         get {
136                                 return (Attributes & MethodAttributes.HideBySig) != 0;
137                         }
138                 }
139                 public Boolean IsAbstract {
140                         get {
141                                 return (Attributes & MethodAttributes.Abstract) != 0;
142                         }
143                 }
144                 public Boolean IsSpecialName {
145                         get {
146                                 int attr = (int)Attributes;
147                                 return (attr & (int)MethodAttributes.SpecialName) != 0;
148                         }
149                 }
150                 public Boolean IsConstructor {
151                         get {
152                                 int attr = (int)Attributes;
153                                 return ((attr & (int)MethodAttributes.RTSpecialName) != 0
154                                         && (Name == ".ctor"));
155                         }
156                 }
157
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);
162                         }
163                         if (this is ConstructorBuilder) {
164                                 ConstructorBuilder mb = (ConstructorBuilder)this;
165                                 return mb.get_next_table_index (obj, table, inc);
166                         }
167                         throw new Exception ("Method is not a builder method");
168                 }
169
170 #if NET_2_0 || BOOTSTRAP_NET_2_0
171                 public virtual MethodInfo BindGenericParameters (Type [] types)
172                 {
173                         throw new NotSupportedException ();
174                 }
175
176                 public virtual Type [] GetGenericArguments ()
177                 {
178                         throw new NotSupportedException ();
179                 }
180
181                 public virtual MethodInfo GetGenericMethodDefinition ()
182                 {
183                         throw new NotSupportedException ();
184                 }
185
186                 public virtual bool Mono_IsInflatedMethod {
187                         get {
188                                 throw new NotSupportedException ();
189                         }
190                 }
191
192                 public virtual bool HasGenericParameters {
193                         get {
194                                 throw new NotSupportedException ();
195                         }
196                 }
197
198                 public virtual bool IsGenericMethodDefinition {
199                         get {
200                                 throw new NotSupportedException ();
201                         }
202                 }
203 #endif
204         }
205 }