GenericParameter.cs: override Module properly
[mcs.git] / class / Mono.Posix / Mono.Remoting.Channels.Unix / UnixBinaryCore.cs
blob87edbbbb7a94b38ac4e6c8aee56e8a95ae7738bd
1 //
2 // Mono.Remoting.Channels.Unix.BinaryCore.cs
3 //
4 // Author: Lluis Sanchez Gual (lluis@novell.com)
5 //
6 // 2005 (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;
31 using System.Reflection;
32 using System.Collections;
33 using System.Runtime.Remoting;
34 using System.Runtime.Remoting.Messaging;
35 using System.Runtime.Serialization;
36 using System.Runtime.Serialization.Formatters;
37 using System.Runtime.Serialization.Formatters.Binary;
39 namespace Mono.Remoting.Channels.Unix
41 internal class UnixBinaryCore
43 BinaryFormatter _serializationFormatter;
44 BinaryFormatter _deserializationFormatter;
45 bool _includeVersions = true;
46 bool _strictBinding = false;
47 IDictionary _properties;
49 public static UnixBinaryCore DefaultInstance = new UnixBinaryCore ();
51 public UnixBinaryCore (object owner, IDictionary properties, string[] allowedProperties)
53 _properties = properties;
55 foreach(DictionaryEntry property in properties)
57 string key = (string) property.Key;
58 if (Array.IndexOf (allowedProperties, key) == -1)
59 throw new RemotingException (owner.GetType().Name + " does not recognize '" + key + "' configuration property");
61 switch (key)
63 case "includeVersions":
64 _includeVersions = Convert.ToBoolean (property.Value);
65 break;
67 case "strictBinding":
68 _strictBinding = Convert.ToBoolean (property.Value);
69 break;
73 Init ();
76 public UnixBinaryCore ()
78 _properties = new Hashtable ();
79 Init ();
82 public void Init ()
84 RemotingSurrogateSelector surrogateSelector = new RemotingSurrogateSelector ();
85 StreamingContext context = new StreamingContext (StreamingContextStates.Remoting, null);
87 _serializationFormatter = new BinaryFormatter (surrogateSelector, context);
88 _deserializationFormatter = new BinaryFormatter (null, context);
90 if (!_includeVersions)
92 _serializationFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple;
93 _deserializationFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple;
96 if (!_strictBinding)
98 _serializationFormatter.Binder = SimpleBinder.Instance;
99 _deserializationFormatter.Binder = SimpleBinder.Instance;
103 public BinaryFormatter Serializer
105 get { return _serializationFormatter; }
108 public BinaryFormatter Deserializer
110 get { return _deserializationFormatter; }
113 public IDictionary Properties
115 get { return _properties; }
120 internal class SimpleBinder: SerializationBinder
122 public static SimpleBinder Instance = new SimpleBinder ();
124 public override Type BindToType (String assemblyName, string typeName)
126 Assembly asm;
128 if (assemblyName.IndexOf (',') != -1)
130 // Try using the full name
133 asm = Assembly.Load (assemblyName);
134 if (asm == null) return null;
135 Type t = asm.GetType (typeName);
136 if (t != null) return t;
138 catch {}
141 // Try using the simple name
142 asm = Assembly.LoadWithPartialName (assemblyName);
143 if (asm == null) return null;
144 return asm.GetType (typeName, true);