Mon Feb 11 19:50:27 CET 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / corlib / System.Reflection / MonoMethod.cs
1 //
2 // System.Reflection/MonoMethod.cs
3 // The class used to represent methods from the mono runtime.
4 //
5 // Author:
6 //   Paolo Molaro (lupus@ximian.com)
7 //
8 // (C) 2001 Ximian, Inc.  http://www.ximian.com
9 //
10
11 using System;
12 using System.Globalization;
13 using System.Runtime.CompilerServices;
14 using System.Runtime.InteropServices;
15
16 namespace System.Reflection {
17         internal struct MonoMethodInfo {
18                 internal Type parent;
19                 internal Type ret;
20                 internal string name;
21                 internal MethodAttributes attrs;
22                 internal MethodImplAttributes iattrs;
23
24                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
25                 internal static extern void get_method_info (RuntimeMethodHandle handle, out MonoMethodInfo info);
26                 
27                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
28                 internal static extern ParameterInfo[] get_parameter_info (RuntimeMethodHandle handle);
29         };
30         
31         /*
32          * Note: most of this class needs to be duplicated for the contructor, since
33          * the .NET reflection class hierarchy is so broken.
34          */
35         internal class MonoMethod : MethodInfo {
36                 internal RuntimeMethodHandle mhandle;
37                 
38                 [MonoTODO]
39                 public override MethodInfo GetBaseDefinition() {
40                         return this; /* FIXME */
41                 }
42                 public override Type ReturnType {
43                         get {
44                                 MonoMethodInfo info;
45                                 MonoMethodInfo.get_method_info (mhandle, out info);
46                                 return info.ret;
47                         }
48                 }
49                 public override ICustomAttributeProvider ReturnTypeCustomAttributes { 
50                         get {return null;}
51                 }
52                 
53                 public override MethodImplAttributes GetMethodImplementationFlags() {
54                         MonoMethodInfo info;
55                         MonoMethodInfo.get_method_info (mhandle, out info);
56                         return info.iattrs;
57                 }
58
59                 public override ParameterInfo[] GetParameters() {
60                         return MonoMethodInfo.get_parameter_info (mhandle);
61                 }
62
63                 [MonoTODO]
64                 public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
65                         throw new NotImplementedException ();
66                 }
67
68                 public override RuntimeMethodHandle MethodHandle { 
69                         get {return mhandle;} 
70                 }
71                 public override MethodAttributes Attributes { 
72                         get {
73                                 MonoMethodInfo info;
74                                 MonoMethodInfo.get_method_info (mhandle, out info);
75                                 return info.attrs;
76                         } 
77                 }
78                 
79                 public override Type ReflectedType {
80                         get {
81                                 MonoMethodInfo info;
82                                 MonoMethodInfo.get_method_info (mhandle, out info);
83                                 return info.parent;
84                         }
85                 }
86                 public override Type DeclaringType {
87                         get {
88                                 MonoMethodInfo info;
89                                 MonoMethodInfo.get_method_info (mhandle, out info);
90                                 return info.parent;
91                         }
92                 }
93                 public override string Name {
94                         get {
95                                 MonoMethodInfo info;
96                                 MonoMethodInfo.get_method_info (mhandle, out info);
97                                 return info.name;
98                         }
99                 }
100                 
101                 public override bool IsDefined (Type attribute_type, bool inherit) {
102                         return false;
103                 }
104
105                 public override object[] GetCustomAttributes( bool inherit) {
106                         return null;
107                 }
108                 public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
109                         return null;
110                 }
111
112                 public override string ToString () {
113                         string parms = "";
114                         ParameterInfo[] p = GetParameters ();
115                         for (int i = 0; i < p.Length; ++i) {
116                                 if (i > 0)
117                                         parms = parms + ", ";
118                                 parms = parms + p [i].ParameterType.Name;
119                         }
120                         return Name+"("+parms+")";
121                 }
122         }
123         
124         internal class MonoCMethod : ConstructorInfo {
125                 internal RuntimeMethodHandle mhandle;
126                 
127                 public override MethodImplAttributes GetMethodImplementationFlags() {
128                         MonoMethodInfo info;
129                         MonoMethodInfo.get_method_info (mhandle, out info);
130                         return info.iattrs;
131                 }
132
133                 public override ParameterInfo[] GetParameters() {
134                         return MonoMethodInfo.get_parameter_info (mhandle);
135                 }
136                 
137                 public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
138                         throw new NotImplementedException ();
139                 }
140
141                 public override Object Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
142                         throw new NotImplementedException ();
143                 }
144
145                 public override RuntimeMethodHandle MethodHandle { 
146                         get {return mhandle;} 
147                 }
148                 public override MethodAttributes Attributes { 
149                         get {
150                                 MonoMethodInfo info;
151                                 MonoMethodInfo.get_method_info (mhandle, out info);
152                                 return info.attrs;
153                         } 
154                 }
155                 
156                 public override Type ReflectedType {
157                         get {
158                                 MonoMethodInfo info;
159                                 MonoMethodInfo.get_method_info (mhandle, out info);
160                                 return info.parent;
161                         }
162                 }
163                 public override Type DeclaringType {
164                         get {
165                                 MonoMethodInfo info;
166                                 MonoMethodInfo.get_method_info (mhandle, out info);
167                                 return info.parent;
168                         }
169                 }
170                 public override string Name {
171                         get {
172                                 MonoMethodInfo info;
173                                 MonoMethodInfo.get_method_info (mhandle, out info);
174                                 return info.name;
175                         }
176                 }
177
178                 [MonoTODO]
179                 public override bool IsDefined (Type attribute_type, bool inherit) {
180                         return false;
181                 }
182
183                 [MonoTODO]
184                 public override object[] GetCustomAttributes (bool inherit) {
185                         return null;
186                 }
187
188                 [MonoTODO]
189                 public override object[] GetCustomAttributes (Type attributeType, bool inherit) {
190                         return null;
191                 }
192         }
193 }