2003-12-08 Patrik Torstensson <p@rxc.se>
[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 #if NET_1_2
35                 virtual
36 #endif
37                 public Object Invoke(Object obj, Object[] parameters) {
38                         return Invoke (obj, 0, null, parameters, null);
39                 }
40
41                 public abstract Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture);
42
43                 protected MethodBase()
44                 {
45                 }
46
47                 public abstract RuntimeMethodHandle MethodHandle { get; }
48                 public abstract MethodAttributes Attributes { get; }
49                 public virtual CallingConventions CallingConvention { get {return CallingConventions.Standard;} }
50                 public Boolean IsPublic { 
51                         get {
52                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
53                         }
54                 }
55                 public Boolean IsPrivate {
56                         get {
57                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
58                         }
59                 }
60                 public Boolean IsFamily {
61                         get {
62                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family;
63                         }
64                 }
65                 public Boolean IsAssembly {
66                         get {
67                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly;
68                         }
69                 }
70                 public Boolean IsFamilyAndAssembly {
71                         get {
72                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem;
73                         }
74                 }
75                 public Boolean IsFamilyOrAssembly {
76                         get {
77                                 return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem;
78                         }
79                 }
80                 public Boolean IsStatic {
81                         get {
82                                 return (Attributes & MethodAttributes.Static) != 0;
83                         }
84                 }
85                 public Boolean IsFinal {
86                         get {
87                                 return (Attributes & MethodAttributes.Final) != 0;
88                         }
89                 }
90                 public Boolean IsVirtual {
91                         get {
92                                 return (Attributes & MethodAttributes.Virtual) != 0;
93                         }
94                 }
95                 public Boolean IsHideBySig {
96                         get {
97                                 return (Attributes & MethodAttributes.HideBySig) != 0;
98                         }
99                 }
100                 public Boolean IsAbstract {
101                         get {
102                                 return (Attributes & MethodAttributes.Abstract) != 0;
103                         }
104                 }
105                 public Boolean IsSpecialName {
106                         get {
107                                 int attr = (int)Attributes;
108                                 return (attr & (int)MethodAttributes.SpecialName) != 0;
109                         }
110                 }
111                 public Boolean IsConstructor {
112                         get {
113                                 int attr = (int)Attributes;
114                                 return ((attr & (int)MethodAttributes.RTSpecialName) != 0
115                                         && (Name == ".ctor"));
116                         }
117                 }
118
119                 internal virtual int get_next_table_index (object obj, int table, bool inc) {
120                         if (this is MethodBuilder) {
121                                 MethodBuilder mb = (MethodBuilder)this;
122                                 return mb.get_next_table_index (obj, table, inc);
123                         }
124                         if (this is ConstructorBuilder) {
125                                 ConstructorBuilder mb = (ConstructorBuilder)this;
126                                 return mb.get_next_table_index (obj, table, inc);
127                         }
128                         throw new Exception ("Method is not a builder method");
129                 }
130         }
131 }