added units tests for TextReader ReadLine() and ReadToEnd()
[mono.git] / mcs / class / corlib / System.Runtime.Serialization.Formatters.Binary / ObjectWriter.cs
index 7fdfc9168a2fcc2d710ea7e8ee57e9951cb16c68..f7f71db0fdaf8209d809e9b7a9d18efe6368ef22 100644 (file)
@@ -51,6 +51,16 @@ namespace System.Runtime.Serialization.Formatters.Binary
                {
                        return true;
                }
+
+#if NET_4_0
+               public void BindToName (string assemblyName, string typeName)
+               {
+                       if (assemblyName != null)
+                               TypeAssemblyName = assemblyName;
+                       if (typeName != null)
+                               InstanceTypeName = typeName;
+               }
+#endif
                
                public abstract bool RequiresTypes { get; }
        }
@@ -219,6 +229,9 @@ namespace System.Runtime.Serialization.Formatters.Binary
                StreamingContext _context;
                FormatterAssemblyStyle _assemblyFormat;
                FormatterTypeStyle _typeFormat;
+#if NET_4_0
+               SerializationBinder _binder;
+#endif
                byte[] arrayBuffer;
                int ArrayBufferLength = 4096;
                SerializationObjectManager _manager;
@@ -235,13 +248,16 @@ namespace System.Runtime.Serialization.Formatters.Binary
                        }
                }
                
-               public ObjectWriter (ISurrogateSelector surrogateSelector, StreamingContext context, FormatterAssemblyStyle assemblyFormat, FormatterTypeStyle typeFormat)
+               public ObjectWriter (BinaryFormatter formatter)
                {
-                       _surrogateSelector = surrogateSelector;
-                       _context = context;
-                       _assemblyFormat = assemblyFormat;
-                       _typeFormat = typeFormat;
-                       _manager = new SerializationObjectManager (context);
+                       _surrogateSelector = formatter.SurrogateSelector;
+                       _context = formatter.Context;
+                       _assemblyFormat = formatter.AssemblyFormat;
+                       _typeFormat = formatter.TypeFormat;
+                       _manager = new SerializationObjectManager (formatter.Context);
+#if NET_4_0
+                       _binder = formatter.Binder;
+#endif
                }
 
                public void WriteObjectGraph (BinaryWriter writer, object obj, Header[] headers)
@@ -357,7 +373,12 @@ namespace System.Runtime.Serialization.Formatters.Binary
                private void GetObjectData (object obj, out TypeMetadata metadata, out object data)
                {
                        Type instanceType = obj.GetType();
-
+#if NET_4_0
+                       string binderAssemblyName = null;
+                       string binderTypeName = null;
+                       if (_binder != null)
+                               _binder.BindToName (instanceType, out binderAssemblyName, out binderTypeName);
+#endif
                        // Check if the formatter has a surrogate selector, if it does, 
                        // check if the surrogate selector handles objects of the given type. 
 
@@ -370,6 +391,11 @@ namespace System.Runtime.Serialization.Formatters.Binary
                                        SerializationInfo info = new SerializationInfo (instanceType, new FormatterConverter ());
                                        surrogate.GetObjectData (obj, info, _context);
                                        metadata = new SerializableTypeMetadata (instanceType, info);
+#if NET_4_0
+                                       if (_binder != null)
+                                               metadata.BindToName (binderAssemblyName, binderTypeName);
+#endif
+
                                        data = info;
                                        return;
                                }
@@ -388,6 +414,11 @@ namespace System.Runtime.Serialization.Formatters.Binary
                                SerializationInfo info = new SerializationInfo (instanceType, new FormatterConverter ());
                                ser.GetObjectData (info, _context);
                                metadata = new SerializableTypeMetadata (instanceType, info);
+#if NET_4_0
+                               if (_binder != null)
+                                       metadata.BindToName (binderAssemblyName, binderTypeName);
+#endif
+
                                data = info;
                        } 
                        else 
@@ -398,6 +429,11 @@ namespace System.Runtime.Serialization.Formatters.Binary
                                        // Don't cache metadata info when the Context property is not null sice
                                        // we can't control the number of possible contexts in this case
                                        metadata = new MemberTypeMetadata (instanceType, _context);
+#if NET_4_0
+                                       if (_binder != null)
+                                               metadata.BindToName (binderAssemblyName, binderTypeName);
+#endif
+
                                        return;
                                }
                                
@@ -420,6 +456,10 @@ namespace System.Runtime.Serialization.Formatters.Binary
 
                                        if (metadata == null) {
                                                metadata = CreateMemberTypeMetadata (instanceType);
+#if NET_4_0
+                                               if (_binder != null)
+                                                       metadata.BindToName (binderAssemblyName, binderTypeName);
+#endif
                                        }
 
                                        typesTable [instanceType] = metadata;