2 // System.Runtime.Remoting.Channels.BinaryCore.cs
4 // Author: Lluis Sanchez Gual (lluis@ximian.com)
6 // 2003 (C) Copyright, Novell, Inc.
9 using System.Collections;
10 using System.Runtime.Remoting.Messaging;
11 using System.Runtime.Serialization;
12 using System.Runtime.Serialization.Formatters;
13 using System.Runtime.Serialization.Formatters.Binary;
15 namespace System.Runtime.Remoting.Channels
17 internal class BinaryCore
19 BinaryFormatter _serializationFormatter;
20 BinaryFormatter _deserializationFormatter;
21 bool _includeVersions = true;
22 bool _strictBinding = false;
25 TypeFilterLevel _filterLevel = TypeFilterLevel.Low;
28 public static BinaryCore DefaultInstance = new BinaryCore ();
30 public BinaryCore (object owner, IDictionary properties, string[] allowedProperties)
32 foreach(DictionaryEntry property in properties)
34 string key = (string) property.Key;
35 if (Array.IndexOf (allowedProperties, key) == -1)
36 throw new RemotingException (owner.GetType().Name + " does not recognize '" + key + "' configuration property");
40 case "includeVersions":
41 _includeVersions = Convert.ToBoolean (property.Value);
45 _strictBinding = Convert.ToBoolean (property.Value);
49 case "typeFilterLevel":
50 if (property.Value is TypeFilterLevel)
51 _filterLevel = (TypeFilterLevel) property.Value;
53 string s = (string) property.Value;
54 _filterLevel = (TypeFilterLevel) Enum.Parse (typeof(TypeFilterLevel), s);
72 RemotingSurrogateSelector surrogateSelector = new RemotingSurrogateSelector ();
73 StreamingContext context = new StreamingContext (StreamingContextStates.Remoting, null);
75 _serializationFormatter = new BinaryFormatter (surrogateSelector, context);
76 _deserializationFormatter = new BinaryFormatter (null, context);
79 _serializationFormatter.FilterLevel = _filterLevel;
80 _deserializationFormatter.FilterLevel = _filterLevel;
83 if (!_includeVersions)
85 _serializationFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple;
86 _deserializationFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple;
91 _serializationFormatter.Binder = ChannelCore.SimpleBinder;
92 _deserializationFormatter.Binder = ChannelCore.SimpleBinder;
96 public BinaryFormatter Serializer
98 get { return _serializationFormatter; }
101 public BinaryFormatter Deserializer
103 get { return _deserializationFormatter; }
107 public TypeFilterLevel TypeFilterLevel
109 get { return _filterLevel; }