(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Runtime.Remoting / System.Runtime.Remoting.Channels / BinaryCore.cs
blobd7177a3786059eb5b86e63d597acf8df085156d9
1 //
2 // System.Runtime.Remoting.Channels.BinaryCore.cs
3 //
4 // Author: Lluis Sanchez Gual (lluis@ximian.com)
5 //
6 // 2003 (C) Copyright, Novell, Inc.
7 //
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Collections;
31 using System.Runtime.Remoting.Messaging;
32 using System.Runtime.Serialization;
33 using System.Runtime.Serialization.Formatters;
34 using System.Runtime.Serialization.Formatters.Binary;
36 namespace System.Runtime.Remoting.Channels
38 internal class BinaryCore
40 BinaryFormatter _serializationFormatter;
41 BinaryFormatter _deserializationFormatter;
42 bool _includeVersions = true;
43 bool _strictBinding = false;
44 IDictionary _properties;
46 #if NET_1_1
47 TypeFilterLevel _filterLevel = TypeFilterLevel.Low;
48 #endif
50 public static BinaryCore DefaultInstance = new BinaryCore ();
52 public BinaryCore (object owner, IDictionary properties, string[] allowedProperties)
54 _properties = properties;
56 foreach(DictionaryEntry property in properties)
58 string key = (string) property.Key;
59 if (Array.IndexOf (allowedProperties, key) == -1)
60 throw new RemotingException (owner.GetType().Name + " does not recognize '" + key + "' configuration property");
62 switch (key)
64 case "includeVersions":
65 _includeVersions = Convert.ToBoolean (property.Value);
66 break;
68 case "strictBinding":
69 _strictBinding = Convert.ToBoolean (property.Value);
70 break;
72 #if NET_1_1
73 case "typeFilterLevel":
74 if (property.Value is TypeFilterLevel)
75 _filterLevel = (TypeFilterLevel) property.Value;
76 else {
77 string s = (string) property.Value;
78 _filterLevel = (TypeFilterLevel) Enum.Parse (typeof(TypeFilterLevel), s);
80 break;
81 #endif
86 Init ();
89 public BinaryCore ()
91 _properties = new Hashtable ();
92 Init ();
95 public void Init ()
97 RemotingSurrogateSelector surrogateSelector = new RemotingSurrogateSelector ();
98 StreamingContext context = new StreamingContext (StreamingContextStates.Remoting, null);
100 _serializationFormatter = new BinaryFormatter (surrogateSelector, context);
101 _deserializationFormatter = new BinaryFormatter (null, context);
103 #if NET_1_1
104 _serializationFormatter.FilterLevel = _filterLevel;
105 _deserializationFormatter.FilterLevel = _filterLevel;
106 #endif
108 if (!_includeVersions)
110 _serializationFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple;
111 _deserializationFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple;
114 if (!_strictBinding)
116 _serializationFormatter.Binder = ChannelCore.SimpleBinder;
117 _deserializationFormatter.Binder = ChannelCore.SimpleBinder;
121 public BinaryFormatter Serializer
123 get { return _serializationFormatter; }
126 public BinaryFormatter Deserializer
128 get { return _deserializationFormatter; }
131 public IDictionary Properties
133 get { return _properties; }
136 #if NET_1_1
137 public TypeFilterLevel TypeFilterLevel
139 get { return _filterLevel; }
141 #endif