| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- //
- // System.Reflection/MonoMethod.cs
- // The class used to represent methods from the mono runtime.
- //
- // Author:
- // Paolo Molaro ([email protected])
- //
- // (C) 2001 Ximian, Inc. http://www.ximian.com
- //
- using System;
- using System.Globalization;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
- using System.Runtime.Serialization;
- namespace System.Reflection {
-
- internal struct MonoMethodInfo
- {
- internal Type parent;
- internal Type ret;
- internal MethodAttributes attrs;
- internal MethodImplAttributes iattrs;
- internal CallingConventions callconv;
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern void get_method_info (IntPtr handle, out MonoMethodInfo info);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern ParameterInfo[] get_parameter_info (IntPtr handle);
- };
-
- /*
- * Note: most of this class needs to be duplicated for the contructor, since
- * the .NET reflection class hierarchy is so broken.
- */
- [Serializable()]
- internal class MonoMethod : MethodInfo, ISerializable
- {
- internal IntPtr mhandle;
- string name;
- Type reftype;
- internal MonoMethod () {
- }
- internal MonoMethod (RuntimeMethodHandle mhandle) {
- this.mhandle = mhandle.Value;
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern MonoMethod get_base_definition (MonoMethod method);
- public override MethodInfo GetBaseDefinition ()
- {
- return get_base_definition (this);
- }
- public override Type ReturnType {
- get {
- MonoMethodInfo info;
- MonoMethodInfo.get_method_info (mhandle, out info);
- return info.ret;
- }
- }
- public override ICustomAttributeProvider ReturnTypeCustomAttributes {
- get {
- return new ParameterInfo (ReturnType, this);
- }
- }
-
- public override MethodImplAttributes GetMethodImplementationFlags() {
- MonoMethodInfo info;
- MonoMethodInfo.get_method_info (mhandle, out info);
- return info.iattrs;
- }
- public override ParameterInfo[] GetParameters() {
- return MonoMethodInfo.get_parameter_info (mhandle);
- }
- /*
- * InternalInvoke() receives the parameters corretcly converted by the binder
- * to match the types of the method signature.
- */
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal extern Object InternalInvoke (Object obj, Object[] parameters);
-
- public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
- if (binder == null)
- binder = Binder.DefaultBinder;
- ParameterInfo[] pinfo = GetParameters ();
- if (!Binder.ConvertArgs (binder, parameters, pinfo, culture))
- throw new ArgumentException ("parameters");
- try {
- return InternalInvoke (obj, parameters);
- } catch (TargetException) {
- throw;
- } catch (Exception e) {
- throw new TargetInvocationException (e);
- }
- }
- public override RuntimeMethodHandle MethodHandle {
- get {return new RuntimeMethodHandle (mhandle);}
- }
- public override MethodAttributes Attributes {
- get {
- MonoMethodInfo info;
- MonoMethodInfo.get_method_info (mhandle, out info);
- return info.attrs;
- }
- }
- public override CallingConventions CallingConvention {
- get {
- MonoMethodInfo info;
- MonoMethodInfo.get_method_info (mhandle, out info);
- return info.callconv;
- }
- }
-
- public override Type ReflectedType {
- get {
- return reftype;
- }
- }
- public override Type DeclaringType {
- get {
- MonoMethodInfo info;
- MonoMethodInfo.get_method_info (mhandle, out info);
- return info.parent;
- }
- }
- public override string Name {
- get {
- return name;
- }
- }
-
- public override bool IsDefined (Type attributeType, bool inherit) {
- return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
- }
- public override object[] GetCustomAttributes( bool inherit) {
- return MonoCustomAttrs.GetCustomAttributes (this, inherit);
- }
- public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
- return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
- }
- public override string ToString () {
- string parms = "";
- ParameterInfo[] p = GetParameters ();
- for (int i = 0; i < p.Length; ++i) {
- if (i > 0)
- parms = parms + ", ";
- if (p[i].ParameterType.IsClass)
- parms = parms + p[i].ParameterType.Namespace + "." + p[i].ParameterType.Name;
- else
- parms = parms + p[i].ParameterType.Name;
- }
- if (ReturnType.IsClass) {
- return ReturnType.Namespace + "." + ReturnType.Name + " " + Name + "(" + parms + ")";
- }
- return ReturnType.Name + " " + Name + "(" + parms + ")";
- }
-
- // ISerializable
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- ReflectionSerializationHolder.Serialize ( info, Name, ReflectedType, ToString(), MemberTypes.Method);
- }
- #if NET_1_2
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- public override extern Type [] GetGenericArguments ();
- #endif
- }
-
- internal class MonoCMethod : ConstructorInfo, ISerializable
- {
- internal IntPtr mhandle;
- string name;
- Type reftype;
-
- public override MethodImplAttributes GetMethodImplementationFlags() {
- MonoMethodInfo info;
- MonoMethodInfo.get_method_info (mhandle, out info);
- return info.iattrs;
- }
- public override ParameterInfo[] GetParameters() {
- return MonoMethodInfo.get_parameter_info (mhandle);
- }
- /*
- * InternalInvoke() receives the parameters corretcly converted by the binder
- * to match the types of the method signature.
- */
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal extern Object InternalInvoke (Object obj, Object[] parameters);
-
- public override Object Invoke (Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
- if (binder == null)
- binder = Binder.DefaultBinder;
- ParameterInfo[] pinfo = GetParameters ();
- if (!Binder.ConvertArgs (binder, parameters, pinfo, culture))
- throw new ArgumentException ("parameters");
- try {
- return InternalInvoke (obj, parameters);
- } catch (TargetException) {
- throw;
- } catch (Exception e) {
- throw new TargetInvocationException (e);
- }
- }
- public override Object Invoke (BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
- return Invoke (null, invokeAttr, binder, parameters, culture);
- }
- public override RuntimeMethodHandle MethodHandle {
- get {return new RuntimeMethodHandle (mhandle);}
- }
- public override MethodAttributes Attributes {
- get {
- MonoMethodInfo info;
- MonoMethodInfo.get_method_info (mhandle, out info);
- return info.attrs;
- }
- }
- public override CallingConventions CallingConvention {
- get {
- MonoMethodInfo info;
- MonoMethodInfo.get_method_info (mhandle, out info);
- return info.callconv;
- }
- }
-
- public override Type ReflectedType {
- get {
- return reftype;
- }
- }
- public override Type DeclaringType {
- get {
- MonoMethodInfo info;
- MonoMethodInfo.get_method_info (mhandle, out info);
- return info.parent;
- }
- }
- public override string Name {
- get {
- return name;
- }
- }
- public override bool IsDefined (Type attributeType, bool inherit) {
- return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
- }
- public override object[] GetCustomAttributes( bool inherit) {
- return MonoCustomAttrs.GetCustomAttributes (this, inherit);
- }
- public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
- return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
- }
- public override string ToString () {
- string parms = "";
- ParameterInfo[] p = GetParameters ();
- for (int i = 0; i < p.Length; ++i) {
- if (i > 0)
- parms = parms + ", ";
- parms = parms + p [i].ParameterType.Name;
- }
- return "Void "+Name+"("+parms+")";
- }
- // ISerializable
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- ReflectionSerializationHolder.Serialize ( info, Name, ReflectedType, ToString(), MemberTypes.Constructor);
- }
- }
- }
|