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