CustomSerializationBinder Class
Namespace: KGySoft.Serialization.BinaryAssembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.1.0
public sealed class CustomSerializationBinder : SerializationBinder,
ISerializationBinder
Public NotInheritable Class CustomSerializationBinder
Inherits SerializationBinder
Implements ISerializationBinder
public ref class CustomSerializationBinder sealed : public SerializationBinder,
ISerializationBinder
[<SealedAttribute>]
type CustomSerializationBinder =
class
inherit SerializationBinder
interface ISerializationBinder
end
- Inheritance
- Object SerializationBinder CustomSerializationBinder
- Implements
- ISerializationBinder
When serializing, you can assign the AssemblyNameResolver and TypeNameResolver properties to customize
the assembly and type names of a Type to be written into the serialization stream.
When deserializing, you can assign the TypeResolver properties to return a type from an assembly-type name pair.
If the properties above are not assigned or when they return , then the consumer IFormatter instance will use its internal resolve logic.
If TypeResolver is not assigned or can return , then the consumer IFormatter instance
may load assemblies during the deserialization. If the deserialization stream is not from a trusted source, then you should
never return from the assigned delegate of the TypeResolver property. Instead, throw an
exception if a type could not be resolved.
See the security notes at the Remarks section of the BinarySerializationFormatter class for more details.
// deserializing a renamed type
var formatter = new BinaryFormatter(); // or a BinarySerializationFormatter in non-safe mode
formatter.Binder = new CustomSerializationBinder
{
TypeResolver = (asmName, typeName) =>
typeName == "MyNamespace.MyOldClass" ? typeof(MyNewClass) : null
};
return (MyNewClass)formatter.Deserialize(streamContainingOldData);
If the inner structure of the type has also been changed, then you can use the
CustomSerializerSurrogateSelector class.
AssemblyNameResolver |
Gets or sets the custom assembly name resolver logic. It is invoked by the BindToName method.
If returns a non- value, then it will be stored as the custom assembly name for the Type specified by the delegate argument.
|
TypeNameResolver |
Gets or sets the custom type name resolver logic. It is invoked by the BindToName method.
If returns a non- value, then it will be stored as the custom full type name (without the assembly name) for the Type specified by the delegate argument.
|
TypeResolver |
Gets or sets the custom Type resolver logic. It is invoked by the BindToType method
passing the stored assembly and type names in the delegate arguments, respectively.
If returns the formatter will attempt to resolve the names by its default logic.
|