Merge pull request #409 from Alkarex/patch-1
[mono.git] / mcs / class / corlib / System.Reflection.Emit / DynamicMethod.cs
index aea1f20b54ce6e77f7b1713a7b57608bd624d4bd..931573d5449459c3860e103b5dab2811d820ee2c 100644 (file)
@@ -31,7 +31,7 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0 || BOOTSTRAP_NET_2_0
+#if !FULL_AOT_RUNTIME
 
 using System;
 using System.Reflection;
@@ -42,12 +42,11 @@ using System.Runtime.InteropServices;
 
 namespace System.Reflection.Emit {
 
-#if NET_2_0
        [ComVisible (true)]
-#endif
+       [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;
@@ -64,12 +63,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) {
                }
@@ -113,9 +113,12 @@ namespace System.Reflection.Emit {
                                        if (parameterTypes [i] == null)
                                                throw new ArgumentException ("Parameter " + i + " is null", "parameterTypes");
                        }
+                       if (owner != null && (owner.IsArray || owner.IsInterface)) {
+                               throw new ArgumentException ("Owner can't be an array or an interface.");
+                       }
 
                        if (m == null)
-                               m = AnonHostModuleHolder.anon_host_module;
+                               m = AnonHostModuleHolder.AnonHostModule;
 
                        this.name = name;
                        this.attributes = attributes | MethodAttributes.Static;
@@ -130,12 +133,9 @@ 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 || (ILGenerator.Mono_GetCurrentOffset (ilgen) == 0))
+                               if (ilgen == null || ilgen.ILOffset == 0)
                                        throw new InvalidOperationException ("Method '" + name + "' does not have a method body.");
 
                                ilgen.label_fixup ();
@@ -161,11 +161,6 @@ namespace System.Reflection.Emit {
                        }
                }
 
-               ~DynamicMethod ()
-               {
-                       destroy_dynamic_method (this);
-               }
-
                [ComVisible (true)]
                public Delegate CreateDelegate (Type delegateType)
                {
@@ -224,9 +219,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 () {
@@ -259,6 +255,15 @@ namespace System.Reflection.Emit {
                        }
                        return retval;
                }
+               
+               internal override int GetParameterCount ()
+               {
+                       return parameters == null ? 0 : parameters.Length;
+               }               
+
+               internal override Type GetParameterType (int pos) {
+                       return parameters [pos];
+               }
 
                /*
                public override object Invoke (object obj, object[] parameters) {
@@ -411,6 +416,12 @@ namespace System.Reflection.Emit {
 
                                anon_host_module = ab.GetManifestModule ();
                        }
+
+                       public static Module AnonHostModule {
+                               get {
+                                       return anon_host_module;
+                               }
+                       }
                }
        }
 
@@ -430,7 +441,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);
                }