XmlSerializerSerialize(XmlWriter, Object, XmlSerializationOptions) Method

Serializes the object passed in obj by the provided XmlWriter object.

Definition

Namespace: KGySoft.Serialization.Xml
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.1.0
C#
public static void Serialize(
	XmlWriter writer,
	Object? obj,
	XmlSerializationOptions options = XmlSerializationOptions.CompactSerializationOfPrimitiveArrays|XmlSerializationOptions.EscapeNewlineCharacters
)

Parameters

writer  XmlWriter
A preconfigured XmlWriter object that will be used for serialization. The writer must be in proper state to serialize obj properly and will just be flushed but not closed after serialization.
obj  Object
The Object to serialize.
options  XmlSerializationOptions  (Optional)
Options for serialization. This parameter is optional.
Default value: CompactSerializationOfPrimitiveArrays, EscapeNewlineCharacters

Exceptions

ArgumentNullExceptionwriter must not be null.
InvalidOperationExceptionThe state of writer is wrong or writer is closed.
EncoderFallbackExceptionThere is a character in the buffer that is a valid XML character but is not valid for the output encoding. For example, if the output encoding is ASCII but public properties of a class contain non-ASCII characters, an EncoderFallbackException is thrown. Such characters are escaped by character entity references in values when possible.
NotSupportedExceptionRoot object is a read-only collection.
ReflectionExceptionThe object hierarchy to serialize contains circular reference.
-or-
Serialization is not supported with provided options

See Also