Merge pull request #5636 from BrzVlad/fix-xmm-scan
[mono.git] / mcs / class / corlib / System.Reflection.Emit / AssemblyBuilder.cs
index 6a6fcd36f5abe114d6eaa3751587690b41811a6c..9c642ffa0062445fd98db4fe2ef938197a3fade6 100644 (file)
@@ -257,6 +257,9 @@ namespace System.Reflection.Emit
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                private static extern void basic_init (AssemblyBuilder ab);
 
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               static extern void UpdateNativeCustomAttributes (AssemblyBuilder ab);
+
                /* Keep this in sync with codegen.cs in mcs */
                private const AssemblyBuilderAccess COMPILER_ACCESS = (AssemblyBuilderAccess) 0x800;
 
@@ -384,7 +387,7 @@ namespace System.Reflection.Emit
 
                internal void AddPermissionRequests (PermissionSet required, PermissionSet optional, PermissionSet refused)
                {
-#if !NET_2_1
+#if !MOBILE
                        if (created)
                                throw new InvalidOperationException ("Assembly was already saved.");
 
@@ -466,6 +469,16 @@ namespace System.Reflection.Emit
                        return new AssemblyBuilder (name, null, access, false);
                }
 
+               public static AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, IEnumerable<CustomAttributeBuilder> assemblyAttributes)
+               {
+                       var ab = DefineDynamicAssembly (name, access);
+                       foreach (var attr in  assemblyAttributes) {
+                               ab.SetCustomAttribute (attr);
+                       }
+
+                       return ab;
+               }
+
                public ModuleBuilder DefineDynamicModule (string name)
                {
                        return DefineDynamicModule (name, name, false, true);
@@ -939,6 +952,12 @@ namespace System.Reflection.Emit
                                cattrs = new CustomAttributeBuilder [1];
                                cattrs [0] = customBuilder;
                        }
+
+                       /*
+                       Only update the native list of custom attributes if we're adding one that is known to change dynamic execution behavior.
+                       */
+                       if (customBuilder.Ctor != null && customBuilder.Ctor.DeclaringType == typeof (System.Runtime.CompilerServices.RuntimeCompatibilityAttribute))
+                               UpdateNativeCustomAttributes (this);
                }
 
                [ComVisible (true)]
@@ -1041,7 +1060,7 @@ namespace System.Reflection.Emit
                /*Warning, @typeArguments must be a mscorlib internal array. So make a copy before passing it in*/
                internal Type MakeGenericType (Type gtd, Type[] typeArguments)
                {
-                       return new MonoGenericClass (gtd, typeArguments);
+                       return new TypeBuilderInstantiation (gtd, typeArguments);
                }
 
                void _AssemblyBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
@@ -1114,8 +1133,7 @@ namespace System.Reflection.Emit
 
                public override AssemblyName GetName (bool copiedName)
                {
-                       AssemblyName aname = new AssemblyName ();
-                       FillName (this, aname);
+                       var aname = AssemblyName.Create (this, false);
 
                        if (sn != null) {
                                aname.SetPublicKey (sn.PublicKey);