Merge pull request #214 from QuickJack/cd2c570c5543963d987f51080218715407c5d4b9
[mono.git] / mcs / class / corlib / System.Reflection.Emit / DynamicMethod.cs
index 44d4f374665d031a3e0736f551016bd10adecf0d..b038897d1db4f765f0e304104703a4a060ecbad8 100644 (file)
@@ -42,9 +42,10 @@ using System.Runtime.InteropServices;
 namespace System.Reflection.Emit {
 
        [ComVisible (true)]
+       [StructLayout (LayoutKind.Sequential)]
        public sealed class DynamicMethod : MethodInfo {
 
-#pragma warning disable 169, 414
+#pragma warning disable 169, 414, 649
                #region Sync with reflection.h
                private RuntimeMethodHandle mhandle;
                private string name;
@@ -61,12 +62,13 @@ namespace System.Reflection.Emit {
                private IntPtr referenced_by;
                private Type owner;
                #endregion
-#pragma warning restore 169, 414
+#pragma warning restore 169, 414, 649
                
                private Delegate deleg;
                private MonoMethod method;
                private ParameterBuilder[] pinfo;
                internal bool creating;
+               private DynamicILInfo il_info;
 
                public DynamicMethod (string name, Type returnType, Type[] parameterTypes, Module m) : this (name, returnType, parameterTypes, m, false) {
                }
@@ -112,7 +114,7 @@ namespace System.Reflection.Emit {
                        }
 
                        if (m == null)
-                               m = AnonHostModuleHolder.anon_host_module;
+                               m = AnonHostModuleHolder.AnonHostModule;
 
                        this.name = name;
                        this.attributes = attributes | MethodAttributes.Static;
@@ -127,9 +129,6 @@ namespace System.Reflection.Emit {
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                private extern void create_dynamic_method (DynamicMethod m);
 
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               private extern void destroy_dynamic_method (DynamicMethod m);
-
                private void CreateDynMethod () {
                        if (mhandle.Value == IntPtr.Zero) {
                                if (ilgen == null || ilgen.ILOffset == 0)
@@ -158,11 +157,6 @@ namespace System.Reflection.Emit {
                        }
                }
 
-               ~DynamicMethod ()
-               {
-                       destroy_dynamic_method (this);
-               }
-
                [ComVisible (true)]
                public Delegate CreateDelegate (Type delegateType)
                {
@@ -221,9 +215,10 @@ namespace System.Reflection.Emit {
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO("Not implemented")]
                public DynamicILInfo GetDynamicILInfo () {
-                       throw new NotImplementedException ();
+                       if (il_info == null)
+                               il_info = new DynamicILInfo (this);
+                       return il_info;
                }
 
                public ILGenerator GetILGenerator () {
@@ -262,6 +257,10 @@ namespace System.Reflection.Emit {
                        return parameters == null ? 0 : parameters.Length;
                }               
 
+               internal override Type GetParameterType (int pos) {
+                       return parameters [pos];
+               }
+
                /*
                public override object Invoke (object obj, object[] parameters) {
                        CreateDynMethod ();
@@ -413,6 +412,12 @@ namespace System.Reflection.Emit {
 
                                anon_host_module = ab.GetManifestModule ();
                        }
+
+                       public static Module AnonHostModule {
+                               get {
+                                       return anon_host_module;
+                               }
+                       }
                }
        }
 
@@ -432,7 +437,7 @@ namespace System.Reflection.Emit {
                        throw new InvalidOperationException ();
                }
 
-               public int GetToken (MemberInfo member) {
+               public int GetToken (MemberInfo member, bool create_open_instance) {
                        return m.AddRef (member);
                }