KGy SOFT

AnyObjectSerializerWrapper Class

KGy SOFT Core Libraries Help
Provides a wrapper class for serializing any kind of object, including the ones that are not marked by the SerializableAttribute, or which are not supported by BinaryFormatter. Can be useful when an object cannot be serialized by BinarySerializationFormatter so a BinaryFormatter must be used. When this object is deserialized, the clone of the wrapped original object is returned.
See the Remarks section for details.
Inheritance Hierarchy

SystemObject
  KGySoft.Serialization.BinaryAnyObjectSerializerWrapper

Namespace:  KGySoft.Serialization.Binary
Assembly:  KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 5.0.0
Syntax

[SerializableAttribute]
public sealed class AnyObjectSerializerWrapper : ISerializable, 
	IObjectReference

The AnyObjectSerializerWrapper type exposes the following members.

Constructors

  NameDescription
Public methodAnyObjectSerializerWrapper
Creates a new instance of AnyObjectSerializerWrapper with the provided object to be serialized.
Top
Methods

  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
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

Since BinarySerializationFormatter supports serialization of any class, this object is not necessarily needed when BinarySerializationFormatter is used.

In .NET Framework this class supports serialization of remote objects, too.

Caution note Caution

This class cannot guarantee that an object serialized in a framework can be deserialized in another one. For such cases some text-based serialization might be better (see also the XmlSerializer).

In .NET Core the ISerializable implementation of some types throw a PlatformNotSupportedException. For such cases setting the forceSerializationByFields in the constructor can be a solution.

For a more flexible customization use the CustomSerializerSurrogateSelector class instead.

See Also

Reference