* BinaryFormatter.cs, MessageFormatter.cs, ObjectReader.cs: Added support
authorLluis Sanchez <lluis@novell.com>
Fri, 21 Nov 2003 16:57:11 +0000 (16:57 -0000)
committerLluis Sanchez <lluis@novell.com>
Fri, 21 Nov 2003 16:57:11 +0000 (16:57 -0000)
  for TypeFilter property.

svn path=/trunk/mcs/; revision=20312

mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs
mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ChangeLog
mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/MessageFormatter.cs
mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs

index f3d92a6e7f85071eb11593e42927b1d2ea29472b..7a2c3a7b1825c8d4a9fe8a73a0d01ad819d5fb31 100755 (executable)
@@ -22,6 +22,10 @@ namespace System.Runtime.Serialization.Formatters.Binary {
                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 +88,14 @@ namespace System.Runtime.Serialization.Formatters.Binary {
                        }
                }
 
+#if NET_1_1
+               public TypeFilterLevel FilterLevel 
+               {
+                       get { return filter_level; }
+                       set { filter_level = value; }
+               }
+#endif
+
                public object Deserialize(Stream serializationStream)
                {
                        return Deserialize (serializationStream, null);
@@ -112,13 +124,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 +154,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)
index 1e142bf69729fc9885251d0944f1180d78393624..2069410bd855fd0668a0ab61fb87ab79d69005a6 100755 (executable)
@@ -1,3 +1,7 @@
+
+       * BinaryFormatter.cs, MessageFormatter.cs, ObjectReader.cs: Added support
+         for TypeFilter property.
+
 2003-11-16  Lluis Sanchez Gual <lluis@ximian.com>
 
        * BinaryFormatter.cs, MessageFormatter.cs, ObjectWriter.cs: 
index 4a1f14f72b50cb075b754e25e4031a9d6518ce79..78cecd18c75529caaf2c62975005f6f67dee8d0c 100644 (file)
@@ -245,7 +245,7 @@ namespace System.Runtime.Serialization.Formatters.Binary
                                writer.Write ((byte) BinaryElement.End);\r
                }\r
 \r
-               public static object ReadMethodCall (BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, ISurrogateSelector surrogateSelector, StreamingContext context, SerializationBinder binder)\r
+               public static object ReadMethodCall (BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, BinaryFormatter formatter)\r
                {\r
                        BinaryElement elem = (BinaryElement)reader.ReadByte();  // The element code\r
                        if (elem != BinaryElement.MethodCall) throw new SerializationException("Invalid format. Expected BinaryElement.MethodCall, found " +  elem);\r
@@ -284,7 +284,7 @@ namespace System.Runtime.Serialization.Formatters.Binary
 
                        if ((flags & MethodFlags.NeedsInfoArrayMask) > 0)\r
                        {\r
-                               ObjectReader objectReader = new ObjectReader(surrogateSelector, context, binder);\r
+                               ObjectReader objectReader = new ObjectReader (formatter);\r
 \r
                                object result;\r
                                objectReader.ReadObjectGraph (reader, hasHeaders, out result, out headers);\r
@@ -339,7 +339,7 @@ namespace System.Runtime.Serialization.Formatters.Binary
                        return call;
                }\r
 \r
-               public static object ReadMethodResponse (BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, IMethodCallMessage methodCallMessage, ISurrogateSelector surrogateSelector, StreamingContext context, SerializationBinder binder)\r
+               public static object ReadMethodResponse (BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, IMethodCallMessage methodCallMessage, BinaryFormatter formatter)\r
                {\r
                        BinaryElement elem = (BinaryElement)reader.ReadByte();  // The element code\r
                        if (elem != BinaryElement.MethodResponse) throw new SerializationException("Invalid format. Expected BinaryElement.MethodResponse, found " +  elem);\r
@@ -382,7 +382,7 @@ namespace System.Runtime.Serialization.Formatters.Binary
                        {\r
                                // There objects that need to be deserialized using an ObjectReader\r
 \r
-                               ObjectReader objectReader = new ObjectReader(surrogateSelector, context, binder);\r
+                               ObjectReader objectReader = new ObjectReader (formatter);\r
                                object result;\r
                                objectReader.ReadObjectGraph (reader, hasHeaders, out result, out headers);\r
                                object[] msgInfo = (object[]) result;\r
index 0e4c67935a72f7b54140e72b7063154ed0b1754c..262cd10a5f792f0eae5295843d223464dbd08558 100644 (file)
@@ -19,9 +19,14 @@ namespace System.Runtime.Serialization.Formatters.Binary
 {\r
        internal class ObjectReader\r
        {\r
+               BinaryFormatter _formatter;\r
                ISurrogateSelector _surrogateSelector;\r
                StreamingContext _context;\r
                SerializationBinder _binder;\r
+               \r
+#if NET_1_1\r
+               TypeFilterLevel _filterLevel;\r
+#endif\r
 \r
                ObjectManager _manager;\r
                Hashtable _registeredAssemblies = new Hashtable();\r
@@ -47,12 +52,17 @@ namespace System.Runtime.Serialization.Formatters.Binary
                        public int NullCount;\r
                }\r
 \r
-               public ObjectReader(ISurrogateSelector surrogateSelector, StreamingContext context, SerializationBinder binder)\r
+               public ObjectReader (BinaryFormatter formatter)\r
                {\r
-                       _manager = new ObjectManager (surrogateSelector, context);\r
-                       _surrogateSelector = surrogateSelector;\r
-                       _context = context;\r
-                       _binder = binder;\r
+                       _formatter = formatter;\r
+                       _surrogateSelector = formatter.SurrogateSelector;\r
+                       _context = formatter.Context;\r
+                       _binder = formatter.Binder;\r
+                       _manager = new ObjectManager (_surrogateSelector, _context);\r
+                       \r
+#if NET_1_1\r
+                       _filterLevel = formatter.FilterLevel;\r
+#endif\r
                }\r
 \r
                public void ReadObjectGraph (BinaryReader reader, bool readHeaders, out object result, out Header[] headers)\r
@@ -214,7 +224,13 @@ namespace System.Runtime.Serialization.Formatters.Binary
 \r
                private void ReadObjectContent (BinaryReader reader, TypeMetadata metadata, long objectId, out object objectInstance, out SerializationInfo info)\r
                {\r
-                       objectInstance = FormatterServices.GetUninitializedObject (metadata.Type);\r
+#if NET_1_1\r
+                       if (_filterLevel == TypeFilterLevel.Low)\r
+                               objectInstance = FormatterServices.GetSafeUninitializedObject (metadata.Type);\r
+                       else\r
+#endif\r
+                               objectInstance = FormatterServices.GetUninitializedObject (metadata.Type);\r
+                               \r
                        info = metadata.NeedsSerializationInfo ? new SerializationInfo(metadata.Type, new FormatterConverter()) : null;\r
 \r
                        if (metadata.MemberNames != null)\r