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 [MethodImplAttribute(MethodImplOptions.InternalCall)]
46 internal static extern MonoMethod get_base_definition (MonoMethod method);
48 public override MethodInfo GetBaseDefinition ()
50 return get_base_definition (this);
53 public override Type ReturnType {
56 MonoMethodInfo.get_method_info (mhandle, out info);
60 public override ICustomAttributeProvider ReturnTypeCustomAttributes {
62 return new ParameterInfo (ReturnType, this);
66 public override MethodImplAttributes GetMethodImplementationFlags() {
68 MonoMethodInfo.get_method_info (mhandle, out info);
72 public override ParameterInfo[] GetParameters() {
73 return MonoMethodInfo.get_parameter_info (mhandle);
77 * InternalInvoke() receives the parameters corretcly converted by the binder
78 * to match the types of the method signature.
80 [MethodImplAttribute(MethodImplOptions.InternalCall)]
81 internal extern Object InternalInvoke (Object obj, Object[] parameters);
83 public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
85 binder = Binder.DefaultBinder;
86 ParameterInfo[] pinfo = GetParameters ();
87 if (!Binder.ConvertArgs (binder, parameters, pinfo, culture))
88 throw new ArgumentException ("parameters");
90 return InternalInvoke (obj, parameters);
91 } catch (TargetException) {
93 } catch (Exception e) {
94 throw new TargetInvocationException (e);
98 public override RuntimeMethodHandle MethodHandle {
99 get {return new RuntimeMethodHandle (mhandle);}
101 public override MethodAttributes Attributes {
104 MonoMethodInfo.get_method_info (mhandle, out info);
109 public override CallingConventions CallingConvention {
112 MonoMethodInfo.get_method_info (mhandle, out info);
113 return info.callconv;
117 public override Type ReflectedType {
122 public override Type DeclaringType {
125 MonoMethodInfo.get_method_info (mhandle, out info);
129 public override string Name {
135 public override bool IsDefined (Type attributeType, bool inherit) {
136 return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
139 public override object[] GetCustomAttributes( bool inherit) {
140 return MonoCustomAttrs.GetCustomAttributes (this, inherit);
142 public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
143 return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
146 public override string ToString () {
148 ParameterInfo[] p = GetParameters ();
149 for (int i = 0; i < p.Length; ++i) {
151 parms = parms + ", ";
152 if (p[i].ParameterType.IsClass)
153 parms = parms + p[i].ParameterType.Namespace + "." + p[i].ParameterType.Name;
155 parms = parms + p[i].ParameterType.Name;
157 if (ReturnType.IsClass) {
158 return ReturnType.Namespace + "." + ReturnType.Name + " " + Name + "(" + parms + ")";
160 return ReturnType.Name + " " + Name + "(" + parms + ")";
165 public void GetObjectData(SerializationInfo info, StreamingContext context)
\r
167 ReflectionSerializationHolder.Serialize ( info, Name, ReflectedType, ToString(), MemberTypes.Method);
\r
171 [MethodImplAttribute(MethodImplOptions.InternalCall)]
172 public override extern Type [] GetGenericArguments ();
176 internal class MonoCMethod : ConstructorInfo, ISerializable
\r
178 internal IntPtr mhandle;
182 public override MethodImplAttributes GetMethodImplementationFlags() {
184 MonoMethodInfo.get_method_info (mhandle, out info);
188 public override ParameterInfo[] GetParameters() {
189 return MonoMethodInfo.get_parameter_info (mhandle);
193 * InternalInvoke() receives the parameters corretcly converted by the binder
194 * to match the types of the method signature.
196 [MethodImplAttribute(MethodImplOptions.InternalCall)]
197 internal extern Object InternalInvoke (Object obj, Object[] parameters);
199 public override Object Invoke (Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
201 binder = Binder.DefaultBinder;
202 ParameterInfo[] pinfo = GetParameters ();
203 if (!Binder.ConvertArgs (binder, parameters, pinfo, culture))
204 throw new ArgumentException ("parameters");
206 return InternalInvoke (obj, parameters);
207 } catch (TargetException) {
209 } catch (Exception e) {
210 throw new TargetInvocationException (e);
214 public override Object Invoke (BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
215 return Invoke (null, invokeAttr, binder, parameters, culture);
218 public override RuntimeMethodHandle MethodHandle {
219 get {return new RuntimeMethodHandle (mhandle);}
221 public override MethodAttributes Attributes {
224 MonoMethodInfo.get_method_info (mhandle, out info);
229 public override CallingConventions CallingConvention {
232 MonoMethodInfo.get_method_info (mhandle, out info);
233 return info.callconv;
237 public override Type ReflectedType {
242 public override Type DeclaringType {
245 MonoMethodInfo.get_method_info (mhandle, out info);
249 public override string Name {
255 public override bool IsDefined (Type attributeType, bool inherit) {
256 return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
259 public override object[] GetCustomAttributes( bool inherit) {
260 return MonoCustomAttrs.GetCustomAttributes (this, inherit);
263 public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
264 return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
267 public override string ToString () {
269 ParameterInfo[] p = GetParameters ();
270 for (int i = 0; i < p.Length; ++i) {
272 parms = parms + ", ";
273 parms = parms + p [i].ParameterType.Name;
275 return "Void "+Name+"("+parms+")";
279 public void GetObjectData(SerializationInfo info, StreamingContext context)
\r
281 ReflectionSerializationHolder.Serialize ( info, Name, ReflectedType, ToString(), MemberTypes.Constructor);
\r