2004-04-22 Martin Baulig <martin@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 using System;
11 using System.Globalization;
12 using System.Reflection.Emit;
13 using System.Runtime.CompilerServices;
14 using System.Runtime.InteropServices;
15
16 namespace System.Reflection {
17
18         [Serializable]
19         [ClassInterface(ClassInterfaceType.AutoDual)]
20         public abstract class MethodBase: MemberInfo {
21
22                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
23                 public extern static MethodBase GetCurrentMethod ();
24
25                 public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle)
26                 {
27                         return null;
28                 }
29
30                 public abstract MethodImplAttributes GetMethodImplementationFlags();
31
32                 public abstract ParameterInfo[] GetParameters();
33                 
34                 //
35                 // This is a quick version for our own use. We should override
36                 // it where possible so that it does not allocate an array.
37                 //
38                 internal virtual int GetParameterCount ()
39                 {
40                         ParameterInfo [] pi = GetParameters ();
41                         if (pi == null)
42                                 return 0;
43                         
44                         return pi.Length;
45                 }
46                 
47 #if NET_2_0
48                 virtual
49 #endif
50                 public Object Invoke(Object obj, Object[] parameters) {
51                         return Invoke (obj, 0, null, parameters, null);
52                 }
53
54                 public abstract Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture);
55
56                 protected MethodBase()
57                 {
58                 }
59
60                 public abstract RuntimeMethodHandle MethodHandle { get; }
61                 public abstract MethodAttributes Attributes { get; }
62                 public virtual CallingConventions CallingConvention { get {return CallingConventions.Standard;} }
63                 public Boolean IsPublic { 
64                         get {
65                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
66                         }
67                 }
68                 public Boolean IsPrivate {
69                         get {
70                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
71                         }
72                 }
73                 public Boolean IsFamily {
74                         get {
75                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family;
76                         }
77                 }
78                 public Boolean IsAssembly {
79                         get {
80                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly;
81                         }
82                 }
83                 public Boolean IsFamilyAndAssembly {
84                         get {
85                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem;
86                         }
87                 }
88                 public Boolean IsFamilyOrAssembly {
89                         get {
90                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem;
91                         }
92                 }
93                 public Boolean IsStatic {
94                         get {
95                                 return (Attributes & MethodAttributes.Static) != 0;
96                         }
97                 }
98                 public Boolean IsFinal {
99                         get {
100                                 return (Attributes & MethodAttributes.Final) != 0;
101                         }
102                 }
103                 public Boolean IsVirtual {
104                         get {
105                                 return (Attributes & MethodAttributes.Virtual) != 0;
106                         }
107                 }
108                 public Boolean IsHideBySig {
109                         get {
110                                 return (Attributes & MethodAttributes.HideBySig) != 0;
111                         }
112                 }
113                 public Boolean IsAbstract {
114                         get {
115                                 return (Attributes & MethodAttributes.Abstract) != 0;
116                         }
117                 }
118                 public Boolean IsSpecialName {
119                         get {
120                                 int attr = (int)Attributes;
121                                 return (attr & (int)MethodAttributes.SpecialName) != 0;
122                         }
123                 }
124                 public Boolean IsConstructor {
125                         get {
126                                 int attr = (int)Attributes;
127                                 return ((attr & (int)MethodAttributes.RTSpecialName) != 0
128                                         && (Name == ".ctor"));
129                         }
130                 }
131
132                 internal virtual int get_next_table_index (object obj, int table, bool inc) {
133                         if (this is MethodBuilder) {
134                                 MethodBuilder mb = (MethodBuilder)this;
135                                 return mb.get_next_table_index (obj, table, inc);
136                         }
137                         if (this is ConstructorBuilder) {
138                                 ConstructorBuilder mb = (ConstructorBuilder)this;
139                                 return mb.get_next_table_index (obj, table, inc);
140                         }
141                         throw new Exception ("Method is not a builder method");
142                 }
143
144 #if NET_2_0
145                 public virtual MethodInfo BindGenericParameters (Type [] types)
146                 {
147                         throw new NotSupportedException ();
148                 }
149
150                 public virtual Type [] GetGenericArguments ()
151                 {
152                         throw new NotSupportedException ();
153                 }
154
155                 public virtual MethodInfo GetGenericMethodDefinition ()
156                 {
157                         throw new NotSupportedException ();
158                 }
159
160                 public virtual bool Mono_IsInflatedMethod {
161                         get {
162                                 throw new NotSupportedException ();
163                         }
164                 }
165
166                 public virtual bool HasGenericParameters {
167                         get {
168                                 throw new NotSupportedException ();
169                         }
170                 }
171
172                 public virtual bool IsGenericMethodDefinition {
173                         get {
174                                 throw new NotSupportedException ();
175                         }
176                 }
177 #endif
178         }
179 }