cvs ignores, sorry about the spam
[mono.git] / mcs / class / corlib / System.Runtime.Serialization.Formatters.Binary / BinaryFormatter.cs
index 7309eb923bbce4c6205d4d0e7d8b8a803708a7d2..50f0f6688911293f05a57beccbdade058f40ed97 100755 (executable)
@@ -6,6 +6,29 @@
 //
 // (C) 2002 Ximian, Inc.  http://www.ximian.com
 
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System.Runtime.Serialization.Formatters;
 using System.Runtime.Serialization;
 using System.Reflection;
@@ -14,14 +37,19 @@ using System.IO;
 using System.Runtime.Remoting.Messaging;
 
 namespace System.Runtime.Serialization.Formatters.Binary {
+
        public sealed class BinaryFormatter : IRemotingFormatter, IFormatter 
        {
-               private FormatterAssemblyStyle assembly_format; // TODO: Do something with this
+               private FormatterAssemblyStyle assembly_format = FormatterAssemblyStyle.Full;
                private SerializationBinder binder;
                private StreamingContext context;
                private ISurrogateSelector surrogate_selector;
                private FormatterTypeStyle type_format;                 // TODO: Do something with this
                
+#if NET_1_1
+               private TypeFilterLevel filter_level;
+#endif
+               
                public BinaryFormatter()
                {
                        surrogate_selector=null;
@@ -84,6 +112,15 @@ namespace System.Runtime.Serialization.Formatters.Binary {
                        }
                }
 
+#if NET_1_1
+               [System.Runtime.InteropServices.ComVisible (false)]
+               public TypeFilterLevel FilterLevel 
+               {
+                       get { return filter_level; }
+                       set { filter_level = value; }
+               }
+#endif
+
                public object Deserialize(Stream serializationStream)
                {
                        return Deserialize (serializationStream, null);
@@ -112,13 +149,13 @@ namespace System.Runtime.Serialization.Formatters.Binary {
                        BinaryElement elem = (BinaryElement) reader.PeekChar();
 
                        if (elem == BinaryElement.MethodCall) {
-                               return MessageFormatter.ReadMethodCall (reader, hasHeader, handler, surrogate_selector, context, binder);
+                               return MessageFormatter.ReadMethodCall (reader, hasHeader, handler, this);
                        }
                        else if (elem == BinaryElement.MethodResponse) {
-                               return MessageFormatter.ReadMethodResponse (reader, hasHeader, handler, null, surrogate_selector, context, binder);
+                               return MessageFormatter.ReadMethodResponse (reader, hasHeader, handler, null, this);
                        }
                        else {
-                               ObjectReader serializer = new ObjectReader (surrogate_selector, context, binder);
+                               ObjectReader serializer = new ObjectReader (this);
 
                                object result;
                                Header[] headers;
@@ -142,7 +179,7 @@ namespace System.Runtime.Serialization.Formatters.Binary {
 
                        bool hasHeader;
                        ReadBinaryHeader (reader, out hasHeader);
-                       return MessageFormatter.ReadMethodResponse (reader, hasHeader, handler, methodCallmessage, surrogate_selector, context, binder);
+                       return MessageFormatter.ReadMethodResponse (reader, hasHeader, handler, methodCallmessage, this);
                }
 
                public void Serialize(Stream serializationStream, object graph)
@@ -160,18 +197,32 @@ namespace System.Runtime.Serialization.Formatters.Binary {
                        WriteBinaryHeader (writer, headers!=null);\r
 \r
                        if (graph is IMethodCallMessage) {\r
-                               MessageFormatter.WriteMethodCall (writer, graph, headers, surrogate_selector, context);\r
+                               MessageFormatter.WriteMethodCall (writer, graph, headers, surrogate_selector, context, assembly_format);\r
                        }\r
                        else if (graph is IMethodReturnMessage)  {\r
-                               MessageFormatter.WriteMethodResponse (writer, graph, headers, surrogate_selector, context);\r
+                               MessageFormatter.WriteMethodResponse (writer, graph, headers, surrogate_selector, context, assembly_format);\r
                        }\r
                        else {\r
-                               ObjectWriter serializer = new ObjectWriter (surrogate_selector, context);
+                               ObjectWriter serializer = new ObjectWriter (surrogate_selector, context, assembly_format);
                                serializer.WriteObjectGraph (writer, graph, headers);
                        }
                        writer.Flush();
                }
 \r
+               [MonoTODO]
+               [System.Runtime.InteropServices.ComVisible (false)]
+               public object UnsafeDeserialize(Stream serializationStream, HeaderHandler handler) 
+               {
+                       throw new NotImplementedException ();
+               }
+               
+               [MonoTODO]
+               [System.Runtime.InteropServices.ComVisible (false)]
+               public object UnsafeDeserializeMethodResponse(Stream serializationStream, HeaderHandler handler, IMethodCallMessage methodCallmessage)
+               {
+                       throw new NotImplementedException ();
+               }
+               
                private void WriteBinaryHeader (BinaryWriter writer, bool hasHeaders)\r
                {\r
                        writer.Write ((byte)BinaryElement.Header);\r