KGy SOFT

NameInvariantSurrogateSelector Class

KGy SOFT Core Libraries Help
An ISurrogateSelector implementation that makes possible to serialize and deserialize objects by IFormatters without storing field names. This provides compatibility for obfuscated and non-obfuscated versions of an assembly.
See the Remarks section for details.
Inheritance Hierarchy

SystemObject
  KGySoft.Serialization.BinaryNameInvariantSurrogateSelector

Namespace:  KGySoft.Serialization.Binary
Assembly:  KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 6.0.0-rc.2
Syntax

public class NameInvariantSurrogateSelector : ISurrogateSelector, 
	ISerializationSurrogate

The NameInvariantSurrogateSelector type exposes the following members.

Constructors

  NameDescription
Public methodNameInvariantSurrogateSelector
Initializes a new instance of the NameInvariantSurrogateSelector class
Top
Properties

  NameDescription
Public propertySafeMode
Gets or sets whether it is prohibited to serialize and deserialize types that are not marked by SerializableAttribute.
Default value: .
Top
Methods

  NameDescription
Public methodChainSelector
Specifies the next ISurrogateSelector for surrogates to examine if the current instance does not have a surrogate for the specified type and assembly in the specified context.
Public methodGetNextSelector
Returns the next surrogate selector in the chain.
Public methodGetSurrogate
Finds the surrogate that represents the specified object's type, starting with the specified surrogate selector for the specified serialization context.
Top
Extension Methods

  NameDescription
Public Extension MethodConvert(Type, CultureInfo)Overloaded.
Converts an Object specified in the obj parameter to the desired targetType.
See the Examples section of the generic ConvertTTarget(Object, CultureInfo) overload for an example.
(Defined by ObjectExtensions.)
Public Extension MethodCode exampleConvertTTarget(CultureInfo)Overloaded.
Converts an Object specified in the obj parameter to the desired TTarget.
(Defined by ObjectExtensions.)
Public Extension MethodIn (Defined by ObjectExtensions.)
Public Extension MethodTryConvert(Type, Object)Overloaded.
Tries to convert an Object specified in the obj parameter to the desired targetType.
(Defined by ObjectExtensions.)
Public Extension MethodTryConvert(Type, CultureInfo, Object)Overloaded.
Tries to convert an Object specified in the obj parameter to the desired targetType.
(Defined by ObjectExtensions.)
Public Extension MethodTryConvertTTarget(TTarget)Overloaded.
Tries to convert an Object specified in the obj parameter to the desired TTarget.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example.
(Defined by ObjectExtensions.)
Public Extension MethodTryConvertTTarget(CultureInfo, TTarget)Overloaded.
Tries to convert an Object specified in the obj parameter to the desired TTarget.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example.
(Defined by ObjectExtensions.)
Top
Remarks

Security note Security Note

If you deserialize a stream from an untrusted source make sure that you set the SafeMode property, which prevents supporting non-serializable types.

See also the security notes at the Remarks section of the BinarySerializationFormatter class for more details.

You can use this surrogate selector for any non-primitive types that does not implement ISerializable interface.

Note Note
Versioning by this surrogate selector can be accomplished only if new fields are always defined after the old ones on every level of the hierarchy. You might want to use also the WeakAssemblySerializationBinder class to ignore version information of assemblies on deserialization.
Caution note Caution
Please note that this surrogate selector does not identify field names on deserialization so reordering members may corrupt or fail deserialization.
See Also

Reference