KGy SOFT

XmlSerializationOptions Enumeration

KGy SOFT Core Libraries Help
Options for serializer methods of XmlSerializer class.

Namespace:  KGySoft.Serialization
Assembly:  KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 5.0.0-alpha.1
Syntax

[FlagsAttribute]
public enum XmlSerializationOptions
Members

  Member nameValueDescription
None0

Represents no enabled options.

With every options disabled only those types are serialized, which are guaranteed to be able to deserialized perfectly. Such types are:

FullyQualifiedNames1

If enabled, collection elements and non binary-serialized complex objects will be identified by the assembly qualified type name, otherwise, only by full type name. Using fully qualified names makes possible to restore types that are declared in any external referenced assembly. While using not fully qualified type names makes possible to restore a type declared in the caller assembly even if the version of the assembly has been modified since last serialization.

Default at serialization methods: Disabled

BinarySerializationAsFallback2

If a type cannot be parsed natively and has no TypeConverter with String support, then enabling this option makes possible to store its content in binary format within the XML.

Though trusted collections and objects with only public read-write properties and fields can be serialized with None options as well, using this option will cause to serialize them in binary format, too.

If both BinarySerializationAsFallback and RecursiveSerializationAsFallback options are enabled, then binary serialization has higher priority, except for properties that are marked by Content visibility, which causes the property to be serialized recursively.

Default at serialization methods: Disabled

RecursiveSerializationAsFallback4

If a type cannot be parsed natively, has no TypeConverter with String support or binary serialization is disabled, then enabling this option makes possible to serialize the object by serializing its public properties, fields and collection items recursively. If a property or collection element cannot be serialized, then a SerializationException will be thrown.

Properties can be marked by DesignerSerializationVisibilityAttribute with Content value to indicate that they should be serialized recursively without using this fallback option.

Caution note Caution
Enabling this option will not guarantee that deserialization of the object will be the same as the original instance. Use this option only when serialized types can be restored by setting public properties and fields, and the type has a default constructor. To avoid circular references use DesignerSerializationVisibilityAttribute with Hidden value on back-referencing properties.

If both BinarySerializationAsFallback and RecursiveSerializationAsFallback options are enabled, then binary serialization has higher priority, except for properties that are marked by Content visibility, which causes the property to be serialized recursively.

Key and Value properties of DictionaryEntry and KeyValuePairTKey, TValue instances are always serialized recursively because these are natively supported types.

Default at serialization methods: Disabled

CompactSerializationOfStructures8

If a ValueType (struct) has no TypeConverter and contains no references, then by enabling this option the instance will be serialized in a compact binary form if possible.

Note Note
This option has higher priority than fallback options (BinarySerializationAsFallback and RecursiveSerializationAsFallback), except for DictionaryEntry and KeyValuePairTKey, TValue instances, which are always serialized recursively. This option affects only instances, which have no reference fields at all, or have only String or Array references, which are decorated by MarshalAsAttribute using ByValTStr or ByValArray, respectively.

Default at serialization methods: Disabled

AutoGenerateDefaultValuesAsFallback16

If enabled, then members without DefaultValueAttribute defined, will be treated as if they were decorated by DefaultValueAttribute with the default value of the property type ( for reference types and bitwise zero value of value types). This causes to skip serializing members, whose value equals to the default value of their type.

Default at serialization methods: Disabled

IgnoreDefaultValueAttribute32

Ignores the originally defined DefaultValueAttribute definitions for all of the properties. This causes that all members will be serialized regardless of their values.

Default at serialization methods: Disabled

IgnoreShouldSerialize64

Ignores the presence of ShouldSerialize<PropertyName> methods for all of the members.

Default at serialization methods: Disabled

IgnoreIXmlSerializable128

If enabled, XmlSerializer ignores IXmlSerializable implementations.

Default at serialization methods: Disabled

CompactSerializationOfPrimitiveArrays256

If enabled, then array of primitive types are serialized in a single XML node instead of creating XML nodes for each element in the array.

Default at serialization methods: Enabled

EscapeNewlineCharacters512

Unless a well configured XmlWriter is used, newline characters of string or char values can be lost or changed during deserialization. This flag ensures that newline characters can be always deserialized regardless of the used NewLineHandling value of an XmlWriter.

Default at serialization methods: Enabled

OmitCrcAttribute1024

When this flag is enabled, binary contents will not be protected by a CRC value. Affects CompactSerializationOfPrimitiveArrays, CompactSerializationOfStructures and BinarySerializationAsFallback flags.

Default at serialization methods: Disabled

ExcludeFields2048

By default XmlSerializer includes public fields in serialization, similarly to System.Xml.Serialization.XmlSerializer. By enabling this option, only public properties will be serialized.

Default at serialization methods: Disabled

ForcedSerializationOfReadOnlyMembersAndCollections4096

By default read-only properties and fields are serialized only if they are IXmlSerializable implementations or collections that can be populated. This option forces to serialize read-only fields and properties, as well as collections that are read-only and have no recognizable initializer constructor.

Note Note
Public properties with private setter accessor are serializable even without this option.
Note Note
Read-only collections witch recognizable collection initializer constructor are serializable even without this option.
Caution note Caution
Enabling this option can make it possible that properties without setter accessor will not be able to deserialized. Deserialization will fail if the read-only property returns a  value or its content cannot be restored (eg. it has a simple type or is a read-only collection). Use this option only if an object has to be serialized only for information (eg. in logs) and deserialization is not necessary.

Default at serialization methods: Disabled

See Also

Reference