Merge pull request #495 from nicolas-raoul/fix-for-issue2907-with-no-formatting-changes
[mono.git] / mcs / class / corlib / System.Runtime.Serialization.Formatters.Binary / CodeGenerator.cs
index 92c956733d3e40e9ef40e4d53f7362f45beb445f..fd38471644b2d7ec9f2e23c0e5273b920ceb9dac 100644 (file)
@@ -28,6 +28,7 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+#if !FULL_AOT_RUNTIME
 using System;
 using System.IO;
 using System.Collections;
@@ -41,6 +42,8 @@ namespace System.Runtime.Serialization.Formatters.Binary
        internal class CodeGenerator
        {
                // Code generation
+
+               static object monitor = new object ();
                
                static ModuleBuilder _module;
                
@@ -54,7 +57,14 @@ namespace System.Runtime.Serialization.Formatters.Binary
                        _module = myAsmBuilder.DefineDynamicModule("__MetadataTypesModule", false);
                }
                
-               static public Type GenerateMetadataType (Type type, StreamingContext context)
+               static public Type GenerateMetadataType (Type type, StreamingContext context) {
+                       /* SRE is not thread safe */
+                       lock (monitor) {
+                               return GenerateMetadataTypeInternal (type, context);
+                       }
+               }
+
+               static public Type GenerateMetadataTypeInternal (Type type, StreamingContext context)
                {               
                        string name = type.Name + "__TypeMetadata";
                        string sufix = "";
@@ -75,7 +85,7 @@ namespace System.Runtime.Serialization.Formatters.Binary
                        // *********************
                        //      METHOD public constructor (Type t): base (t);
                        
-                       parameters = new Type[0];
+                       parameters = Type.EmptyTypes;
 
                        ConstructorBuilder ctor = typeBuilder.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, parameters);
                        ConstructorInfo baseCtor = typeof(ClrTypeMetadata).GetConstructor (new Type[] { typeof(Type) });
@@ -253,7 +263,7 @@ namespace System.Runtime.Serialization.Formatters.Binary
                                ig.Emit (OpCodes.Ldind_Ref);
                }
 
-               public static void EmitWriteTypeSpec (ILGenerator gen, Type type, string member)
+               static void EmitWriteTypeSpec (ILGenerator gen, Type type, string member)
                {
                        // WARNING Keep in sync with WriteTypeSpec
                        
@@ -341,7 +351,7 @@ namespace System.Runtime.Serialization.Formatters.Binary
                                        break;
                                        
                                case TypeCode.DateTime: 
-                                       gen.EmitCall (OpCodes.Call, typeof(DateTime).GetProperty("Ticks").GetGetMethod(), null);
+                                       gen.EmitCall (OpCodes.Call, typeof(DateTime).GetMethod("ToBinary", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance), null);
                                        EmitWrite (gen, typeof(long));
                                        break;
                                        
@@ -392,3 +402,4 @@ namespace System.Runtime.Serialization.Formatters.Binary
        }
  }
  
+#endif