Move fields from binder to exception
This commit is contained in:
parent
9050af8a03
commit
cd7d3724c3
|
@ -131,29 +131,28 @@ namespace de4dot.code.resources {
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyBinder : SerializationBinder {
|
class MyBinder : SerializationBinder {
|
||||||
public string assemblyName;
|
|
||||||
public string typeName;
|
|
||||||
|
|
||||||
public class OkException : Exception {
|
public class OkException : Exception {
|
||||||
|
public string AssemblyName { get; set; }
|
||||||
|
public string TypeName { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Type BindToType(string assemblyName, string typeName) {
|
public override Type BindToType(string assemblyName, string typeName) {
|
||||||
this.assemblyName = assemblyName;
|
throw new OkException {
|
||||||
this.typeName = typeName;
|
AssemblyName = assemblyName,
|
||||||
throw new OkException();
|
TypeName = typeName,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getSerializedTypeAndAssemblyName(byte[] value, out string assemblyName, out string typeName) {
|
bool getSerializedTypeAndAssemblyName(byte[] value, out string assemblyName, out string typeName) {
|
||||||
var binder = new MyBinder();
|
|
||||||
try {
|
try {
|
||||||
var formatter = new BinaryFormatter();
|
var formatter = new BinaryFormatter();
|
||||||
formatter.Binder = binder;
|
formatter.Binder = new MyBinder();
|
||||||
formatter.Deserialize(new MemoryStream(value));
|
formatter.Deserialize(new MemoryStream(value));
|
||||||
}
|
}
|
||||||
catch (MyBinder.OkException) {
|
catch (MyBinder.OkException ex) {
|
||||||
assemblyName = binder.assemblyName;
|
assemblyName = ex.AssemblyName;
|
||||||
typeName = binder.typeName;
|
typeName = ex.TypeName;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user