**** Merged from MCS ****
[mono-project.git] / mcs / class / corlib / System.Reflection / MethodBase.cs
blob0ddbe90922936c6d94947431d3f6dca41d4ac0eb
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 //
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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.
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;
40 namespace System.Reflection {
42 [Serializable]
43 [ClassInterface(ClassInterfaceType.AutoDual)]
44 public abstract class MethodBase: MemberInfo {
46 [MethodImplAttribute (MethodImplOptions.InternalCall)]
47 public extern static MethodBase GetCurrentMethod ();
49 [MethodImplAttribute (MethodImplOptions.InternalCall)]
50 private extern static MethodBase GetMethodFromHandleInternal(IntPtr handle);
52 public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle) {
53 return GetMethodFromHandleInternal (handle.Value);
56 public abstract MethodImplAttributes GetMethodImplementationFlags();
58 public abstract ParameterInfo[] GetParameters();
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.
64 internal virtual int GetParameterCount ()
66 ParameterInfo [] pi = GetParameters ();
67 if (pi == null)
68 return 0;
70 return pi.Length;
73 [DebuggerHidden]
74 [DebuggerStepThrough]
75 #if NET_2_0 || BOOTSTRAP_NET_2_0
76 virtual
77 #endif
78 public Object Invoke(Object obj, Object[] parameters) {
79 return Invoke (obj, 0, null, parameters, null);
82 public abstract Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture);
84 protected MethodBase()
88 public abstract RuntimeMethodHandle MethodHandle { get; }
89 public abstract MethodAttributes Attributes { get; }
90 public virtual CallingConventions CallingConvention { get {return CallingConventions.Standard;} }
91 public Boolean IsPublic {
92 get {
93 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
96 public Boolean IsPrivate {
97 get {
98 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
101 public Boolean IsFamily {
102 get {
103 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family;
106 public Boolean IsAssembly {
107 get {
108 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly;
111 public Boolean IsFamilyAndAssembly {
112 get {
113 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem;
116 public Boolean IsFamilyOrAssembly {
117 get {
118 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem;
121 public Boolean IsStatic {
122 get {
123 return (Attributes & MethodAttributes.Static) != 0;
126 public Boolean IsFinal {
127 get {
128 return (Attributes & MethodAttributes.Final) != 0;
131 public Boolean IsVirtual {
132 get {
133 return (Attributes & MethodAttributes.Virtual) != 0;
136 public Boolean IsHideBySig {
137 get {
138 return (Attributes & MethodAttributes.HideBySig) != 0;
141 public Boolean IsAbstract {
142 get {
143 return (Attributes & MethodAttributes.Abstract) != 0;
146 public Boolean IsSpecialName {
147 get {
148 int attr = (int)Attributes;
149 return (attr & (int)MethodAttributes.SpecialName) != 0;
152 public Boolean IsConstructor {
153 get {
154 int attr = (int)Attributes;
155 return ((attr & (int)MethodAttributes.RTSpecialName) != 0
156 && (Name == ".ctor"));
160 internal virtual int get_next_table_index (object obj, int table, bool inc) {
161 if (this is MethodBuilder) {
162 MethodBuilder mb = (MethodBuilder)this;
163 return mb.get_next_table_index (obj, table, inc);
165 if (this is ConstructorBuilder) {
166 ConstructorBuilder mb = (ConstructorBuilder)this;
167 return mb.get_next_table_index (obj, table, inc);
169 throw new Exception ("Method is not a builder method");
172 #if NET_2_0 || BOOTSTRAP_NET_2_0
173 public virtual MethodInfo BindGenericParameters (Type [] types)
175 throw new NotSupportedException ();
178 public virtual Type [] GetGenericArguments ()
180 throw new NotSupportedException ();
183 public virtual MethodInfo GetGenericMethodDefinition ()
185 throw new NotSupportedException ();
188 public virtual bool Mono_IsInflatedMethod {
189 get {
190 throw new NotSupportedException ();
194 public virtual bool HasGenericParameters {
195 get {
196 throw new NotSupportedException ();
200 public virtual bool IsGenericMethodDefinition {
201 get {
202 throw new NotSupportedException ();
205 #endif