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;
\r
17 namespace System.Reflection {
19 internal struct MonoMethodInfo
23 internal MethodAttributes attrs;
24 internal MethodImplAttributes iattrs;
26 [MethodImplAttribute(MethodImplOptions.InternalCall)]
27 internal static extern void get_method_info (IntPtr handle, out MonoMethodInfo info);
29 [MethodImplAttribute(MethodImplOptions.InternalCall)]
30 internal static extern ParameterInfo[] get_parameter_info (IntPtr handle);
34 * Note: most of this class needs to be duplicated for the contructor, since
35 * the .NET reflection class hierarchy is so broken.
38 internal class MonoMethod : MethodInfo, ISerializable
\r
40 internal IntPtr mhandle;
44 [MethodImplAttribute(MethodImplOptions.InternalCall)]
45 internal static extern MonoMethod get_base_definition (MonoMethod method);
47 public override MethodInfo GetBaseDefinition ()
49 return get_base_definition (this);
52 public override Type ReturnType {
55 MonoMethodInfo.get_method_info (mhandle, out info);
59 public override ICustomAttributeProvider ReturnTypeCustomAttributes {
61 return new ParameterInfo (ReturnType, this);
65 public override MethodImplAttributes GetMethodImplementationFlags() {
67 MonoMethodInfo.get_method_info (mhandle, out info);
71 public override ParameterInfo[] GetParameters() {
72 return MonoMethodInfo.get_parameter_info (mhandle);
76 * InternalInvoke() receives the parameters corretcly converted by the binder
77 * to match the types of the method signature.
79 [MethodImplAttribute(MethodImplOptions.InternalCall)]
80 internal extern Object InternalInvoke (Object obj, Object[] parameters);
82 public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
84 binder = Binder.DefaultBinder;
85 ParameterInfo[] pinfo = GetParameters ();
86 if (!Binder.ConvertArgs (binder, parameters, pinfo, culture))
87 throw new ArgumentException ("parameters");
89 return InternalInvoke (obj, parameters);
90 } catch (TargetException) {
92 } catch (Exception e) {
93 throw new TargetInvocationException (e);
97 public override RuntimeMethodHandle MethodHandle {
98 get {return new RuntimeMethodHandle (mhandle);}
100 public override MethodAttributes Attributes {
103 MonoMethodInfo.get_method_info (mhandle, out info);
108 public override Type ReflectedType {
113 public override Type DeclaringType {
116 MonoMethodInfo.get_method_info (mhandle, out info);
120 public override string Name {
126 public override bool IsDefined (Type attributeType, bool inherit) {
127 return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
130 public override object[] GetCustomAttributes( bool inherit) {
131 return MonoCustomAttrs.GetCustomAttributes (this, inherit);
133 public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
134 return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
137 public override string ToString () {
139 ParameterInfo[] p = GetParameters ();
140 for (int i = 0; i < p.Length; ++i) {
142 parms = parms + ", ";
143 parms = parms + p [i].ParameterType.Name;
145 return ReturnType.Name+" "+Name+"("+parms+")";
150 public void GetObjectData(SerializationInfo info, StreamingContext context)
\r
152 ReflectionSerializationHolder.Serialize ( info, Name, ReflectedType, ToString(), MemberTypes.Method);
\r
156 internal class MonoCMethod : ConstructorInfo, ISerializable
\r
158 internal IntPtr mhandle;
162 public override MethodImplAttributes GetMethodImplementationFlags() {
164 MonoMethodInfo.get_method_info (mhandle, out info);
168 public override ParameterInfo[] GetParameters() {
169 return MonoMethodInfo.get_parameter_info (mhandle);
173 * InternalInvoke() receives the parameters corretcly converted by the binder
174 * to match the types of the method signature.
176 [MethodImplAttribute(MethodImplOptions.InternalCall)]
177 internal extern Object InternalInvoke (Object obj, Object[] parameters);
179 public override Object Invoke (Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
181 binder = Binder.DefaultBinder;
182 ParameterInfo[] pinfo = GetParameters ();
183 if (!Binder.ConvertArgs (binder, parameters, pinfo, culture))
184 throw new ArgumentException ("parameters");
186 return InternalInvoke (obj, parameters);
187 } catch (TargetException) {
189 } catch (Exception e) {
190 throw new TargetInvocationException (e);
194 public override Object Invoke (BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
195 return Invoke (null, invokeAttr, binder, parameters, culture);
198 public override RuntimeMethodHandle MethodHandle {
199 get {return new RuntimeMethodHandle (mhandle);}
201 public override MethodAttributes Attributes {
204 MonoMethodInfo.get_method_info (mhandle, out info);
209 public override Type ReflectedType {
214 public override Type DeclaringType {
217 MonoMethodInfo.get_method_info (mhandle, out info);
221 public override string Name {
227 public override bool IsDefined (Type attributeType, bool inherit) {
228 return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
231 public override object[] GetCustomAttributes( bool inherit) {
232 return MonoCustomAttrs.GetCustomAttributes (this, inherit);
235 public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
236 return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
239 public override string ToString () {
241 ParameterInfo[] p = GetParameters ();
242 for (int i = 0; i < p.Length; ++i) {
244 parms = parms + ", ";
245 parms = parms + p [i].ParameterType.Name;
247 return "Void "+Name+"("+parms+")";
251 public void GetObjectData(SerializationInfo info, StreamingContext context)
\r
253 ReflectionSerializationHolder.Serialize ( info, Name, ReflectedType, ToString(), MemberTypes.Constructor);
\r