2 // System.Reflection/MonoMethod.cs
3 // The class used to represent methods from the mono runtime.
6 // Paolo Molaro (lupus@ximian.com)
8 // (C) 2001 Ximian, Inc. http://www.ximian.com
12 using System.Globalization;
13 using System.Runtime.CompilerServices;
14 using System.Runtime.InteropServices;
15 using System.Runtime.Serialization;
17 namespace System.Reflection {
19 internal struct MonoMethodInfo
23 internal MethodAttributes attrs;
24 internal MethodImplAttributes iattrs;
25 internal CallingConventions callconv;
27 [MethodImplAttribute(MethodImplOptions.InternalCall)]
28 internal static extern void get_method_info (IntPtr handle, out MonoMethodInfo info);
30 [MethodImplAttribute(MethodImplOptions.InternalCall)]
31 internal static extern ParameterInfo[] get_parameter_info (IntPtr handle);
35 * Note: most of this class needs to be duplicated for the contructor, since
36 * the .NET reflection class hierarchy is so broken.
39 internal class MonoMethod : MethodInfo, ISerializable
\r
41 internal IntPtr mhandle;
45 internal MonoMethod () {
48 internal MonoMethod (RuntimeMethodHandle mhandle) {
49 this.mhandle = mhandle.Value;
52 [MethodImplAttribute(MethodImplOptions.InternalCall)]
53 internal static extern MonoMethod get_base_definition (MonoMethod method);
55 public override MethodInfo GetBaseDefinition ()
57 return get_base_definition (this);
60 public override Type ReturnType {
63 MonoMethodInfo.get_method_info (mhandle, out info);
67 public override ICustomAttributeProvider ReturnTypeCustomAttributes {
69 return new ParameterInfo (ReturnType, this);
73 public override MethodImplAttributes GetMethodImplementationFlags() {
75 MonoMethodInfo.get_method_info (mhandle, out info);
79 public override ParameterInfo[] GetParameters() {
80 return MonoMethodInfo.get_parameter_info (mhandle);
84 * InternalInvoke() receives the parameters corretcly converted by the binder
85 * to match the types of the method signature.
87 [MethodImplAttribute(MethodImplOptions.InternalCall)]
88 internal extern Object InternalInvoke (Object obj, Object[] parameters);
90 public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
92 binder = Binder.DefaultBinder;
93 ParameterInfo[] pinfo = GetParameters ();
94 if (!Binder.ConvertArgs (binder, parameters, pinfo, culture))
95 throw new ArgumentException ("parameters");
97 return InternalInvoke (obj, parameters);
98 } catch (TargetException) {
100 } catch (Exception e) {
101 throw new TargetInvocationException (e);
105 public override RuntimeMethodHandle MethodHandle {
106 get {return new RuntimeMethodHandle (mhandle);}
108 public override MethodAttributes Attributes {
111 MonoMethodInfo.get_method_info (mhandle, out info);
116 public override CallingConventions CallingConvention {
119 MonoMethodInfo.get_method_info (mhandle, out info);
120 return info.callconv;
124 public override Type ReflectedType {
129 public override Type DeclaringType {
132 MonoMethodInfo.get_method_info (mhandle, out info);
136 public override string Name {
142 public override bool IsDefined (Type attributeType, bool inherit) {
143 return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
146 public override object[] GetCustomAttributes( bool inherit) {
147 return MonoCustomAttrs.GetCustomAttributes (this, inherit);
149 public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
150 return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
153 public override string ToString () {
155 ParameterInfo[] p = GetParameters ();
156 for (int i = 0; i < p.Length; ++i) {
158 parms = parms + ", ";
159 if (p[i].ParameterType.IsClass)
160 parms = parms + p[i].ParameterType.Namespace + "." + p[i].ParameterType.Name;
162 parms = parms + p[i].ParameterType.Name;
164 if (ReturnType.IsClass) {
165 return ReturnType.Namespace + "." + ReturnType.Name + " " + Name + "(" + parms + ")";
167 return ReturnType.Name + " " + Name + "(" + parms + ")";
172 public void GetObjectData(SerializationInfo info, StreamingContext context)
\r
174 ReflectionSerializationHolder.Serialize ( info, Name, ReflectedType, ToString(), MemberTypes.Method);
\r
178 [MethodImplAttribute(MethodImplOptions.InternalCall)]
179 public override extern Type [] GetGenericArguments ();
183 internal class MonoCMethod : ConstructorInfo, ISerializable
\r
185 internal IntPtr mhandle;
189 public override MethodImplAttributes GetMethodImplementationFlags() {
191 MonoMethodInfo.get_method_info (mhandle, out info);
195 public override ParameterInfo[] GetParameters() {
196 return MonoMethodInfo.get_parameter_info (mhandle);
200 * InternalInvoke() receives the parameters corretcly converted by the binder
201 * to match the types of the method signature.
203 [MethodImplAttribute(MethodImplOptions.InternalCall)]
204 internal extern Object InternalInvoke (Object obj, Object[] parameters);
206 public override Object Invoke (Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
208 binder = Binder.DefaultBinder;
209 ParameterInfo[] pinfo = GetParameters ();
210 if (!Binder.ConvertArgs (binder, parameters, pinfo, culture))
211 throw new ArgumentException ("parameters");
213 return InternalInvoke (obj, parameters);
214 } catch (TargetException) {
216 } catch (Exception e) {
217 throw new TargetInvocationException (e);
221 public override Object Invoke (BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
222 return Invoke (null, invokeAttr, binder, parameters, culture);
225 public override RuntimeMethodHandle MethodHandle {
226 get {return new RuntimeMethodHandle (mhandle);}
228 public override MethodAttributes Attributes {
231 MonoMethodInfo.get_method_info (mhandle, out info);
236 public override CallingConventions CallingConvention {
239 MonoMethodInfo.get_method_info (mhandle, out info);
240 return info.callconv;
244 public override Type ReflectedType {
249 public override Type DeclaringType {
252 MonoMethodInfo.get_method_info (mhandle, out info);
256 public override string Name {
262 public override bool IsDefined (Type attributeType, bool inherit) {
263 return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
266 public override object[] GetCustomAttributes( bool inherit) {
267 return MonoCustomAttrs.GetCustomAttributes (this, inherit);
270 public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
271 return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
274 public override string ToString () {
276 ParameterInfo[] p = GetParameters ();
277 for (int i = 0; i < p.Length; ++i) {
279 parms = parms + ", ";
280 parms = parms + p [i].ParameterType.Name;
282 return "Void "+Name+"("+parms+")";
286 public void GetObjectData(SerializationInfo info, StreamingContext context)
\r
288 ReflectionSerializationHolder.Serialize ( info, Name, ReflectedType, ToString(), MemberTypes.Constructor);
\r