* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Messaging / System.Messaging / BinaryMessageFormatter.cs
index 937684435a6d0900bfc8562641e7a5f703aabb8b..11ca9507956e74bac8c0550ee21fecfedcb35967 100644 (file)
@@ -1,3 +1,24 @@
+
+//
+// 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.
+//
 \r
 //\r
 // System.Messaging\r
 //\r
 // (C) 2003 Peter Van Isacker\r
 //\r
+\r
 using System;\r
+using System.ComponentModel;\r
 using System.Runtime.Serialization.Formatters;\r
 using System.Runtime.Serialization.Formatters.Binary;\r
 \r
-namespace System.Messaging \r
+namespace System.Messaging\r
 {\r
-       public class BinaryMessageFormatter: IMessageFormatter, ICloneable \r
+       public class BinaryMessageFormatter : IMessageFormatter, ICloneable\r
        {\r
-               public BinaryMessageFormatter()\r
+               private BinaryFormatter _formatter;\r
+\r
+               public BinaryMessageFormatter ()\r
                {\r
-                       TopObjectFormat = FormatterAssemblyStyle.Full;\r
-                       TypeFormat = FormatterTypeStyle.TypesWhenNeeded;\r
+                       _formatter = new BinaryFormatter ();\r
                }\r
-               \r
-               public BinaryMessageFormatter(FormatterAssemblyStyle topObjectFormat, FormatterTypeStyle typeFormat)\r
+\r
+               public BinaryMessageFormatter (FormatterAssemblyStyle topObjectFormat, FormatterTypeStyle typeFormat)\r
                {\r
-                       TopObjectFormat = topObjectFormat;\r
-                       TypeFormat = typeFormat;\r
+                       _formatter = new BinaryFormatter ();\r
+                       _formatter.AssemblyFormat = topObjectFormat;\r
+                       _formatter.TypeFormat = typeFormat;\r
+               }\r
+\r
+               [DefaultValue (0)]\r
+               [MessagingDescription ("MsgTopObjectFormat")]\r
+               public FormatterAssemblyStyle TopObjectFormat {\r
+                       get {\r
+                               return _formatter.AssemblyFormat;\r
+                       }\r
+                       set {\r
+                               _formatter.AssemblyFormat = value;\r
+                       }\r
+               }\r
+\r
+               [DefaultValue (0)]\r
+               [MessagingDescription ("MsgTypeFormat")]\r
+               public FormatterTypeStyle TypeFormat {\r
+                       get {\r
+                               return _formatter.TypeFormat;\r
+                       }\r
+                       set {\r
+                               _formatter.TypeFormat = value;\r
+                       }\r
                }\r
-               \r
-               public FormatterAssemblyStyle TopObjectFormat;\r
-               \r
-               public FormatterTypeStyle TypeFormat;\r
-               \r
-               public bool CanRead(Message message) \r
+\r
+               [MonoTODO ("only return true if body type is binary")]\r
+               public bool CanRead (Message message)\r
                {\r
                        if (message == null)\r
-                               throw new ArgumentNullException();\r
+                               throw new ArgumentNullException ();\r
                        return message.BodyStream.CanRead;\r
                }\r
-               \r
-               public object Read(Message message)\r
+\r
+               [MonoTODO ("throw InvalidOperationException if message body is not binary")]\r
+               public object Read (Message message)\r
                {\r
                        if (message == null)\r
-                               throw new ArgumentNullException();\r
-                               \r
-                       BinaryFormatter bf = new BinaryFormatter();\r
-                       bf.AssemblyFormat = TopObjectFormat;\r
-                       bf.TypeFormat = TypeFormat;\r
-                       return bf.Deserialize(message.BodyStream);\r
+                               throw new ArgumentNullException ();\r
+\r
+                       return _formatter.Deserialize (message.BodyStream);\r
                }\r
-               \r
-               public void Write(Message message, object obj)\r
+\r
+               [MonoTODO ("throw InvalidOperationException if message body is not binary")]\r
+               public void Write (Message message, object obj)\r
                {\r
                        if (message == null)\r
-                               throw new ArgumentNullException();\r
-                               \r
-                       BinaryFormatter bf = new BinaryFormatter();\r
-                       bf.AssemblyFormat = TopObjectFormat;\r
-                       bf.TypeFormat = TypeFormat;             \r
-                       bf.Serialize(message.BodyStream, obj);\r
-               }       \r
-               \r
-               public object Clone()\r
-               {\r
-                       return new BinaryMessageFormatter(TopObjectFormat, TypeFormat);\r
+                               throw new ArgumentNullException ();\r
+\r
+                       _formatter.Serialize (message.BodyStream, obj);\r
                }\r
-               \r
-               [MonoTODO]\r
-               ~BinaryMessageFormatter()\r
+\r
+               public object Clone ()\r
                {\r
+                       return new BinaryMessageFormatter (TopObjectFormat, TypeFormat);\r
                }\r
        }\r
 }\r