12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Reflection;
- using System.Runtime.Serialization;
- namespace SmartCoalApplication.SystemLayer
- {
- public sealed class SerializationFallbackBinder : SerializationBinder
- {
- private List<Assembly> assemblies;
- public SerializationFallbackBinder()
- {
- this.assemblies = new List<Assembly>();
- }
- public void AddAssembly(Assembly assembly)
- {
- this.assemblies.Add(assembly);
- }
- private Type TryBindToType(Assembly assembly, string typeName)
- {
- Type type = assembly.GetType(typeName, false, true);
- return type;
- }
- public override Type BindToType(string assemblyName, string typeName)
- {
- Type type = null;
- foreach (Assembly tryAssembly in this.assemblies)
- {
- type = TryBindToType(tryAssembly, typeName);
- if (type != null)
- {
- break;
- }
- }
- if (type == null)
- {
- string fullTypeName = typeName + ", " + assemblyName;
- try
- {
- type = System.Type.GetType(fullTypeName, false, true);
- }
- catch (FileLoadException)
- {
- type = null;
- }
- }
- return type;
- }
- }
- }
|