internal sealed class MyBinder : SerializationBinder
{
public override Type BindToType(string assemblyName, string typeName)
{
Type ttd = null;
try
{
var toassname = assemblyName.Split(',')[0];
var asmblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (var ass in asmblies)
{
if (ass.FullName.Split(',')[0] == toassname)
{
var types = ass.GetTypes().Where(x => x.ContainsGenericParameters);
ttd = ass.GetType(typeName, false, true);
if (ttd is null)
{
switch (typeName)
{
case "System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[GraphAssembly.Node, GraphAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]":
ttd = typeof(Dictionary<string, Node>);
break;
case "System.Collections.Generic.List`1[[GraphAssembly.Section, GraphAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]":
ttd = typeof(List<Section>);
break;
case "System.Collections.Generic.KeyValuePair`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[GraphAssembly.Node, GraphAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]":
ttd = typeof(System.Collections.Generic.KeyValuePair<string,Node>);
break;
case "System.Collections.Generic.List`1[[GraphAssembly.Cable, GraphAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]":
ttd = typeof(List<Cable>);
break;
default:
Debug.WriteLine($"Не найден тип \"{typeName}\" в сборке {toassname}");
break;
}
}
else break;
}
}
}
catch (System.Exception e)
{
Debug.WriteLine(e.Message);
}
return ttd;
}
}