ICrystalXmlElementSerializer<T>

Namespace: SnowBank.Data.Xml · interface

Implements: ICrystalXmlSerializer<T>

Serializes instances of T as a named element inside a larger document, and names itself

Remarks

The composition surface of a serializer: WriteXml writes a whole document, while WriteXmlElement writes one element a caller has already named, at a depth the caller states. The generated per-type serializers implement this interface; the collection root entry points of CrystalXml (ToText and its seven siblings) compose a document out of it, one element per item.

The two names let a caller compose without guessing: ElementName is what this type calls itself, and CollectionRootName is what a bare sequence of it is called, when the profile has such a convention.

Properties

CollectionRootName

string CollectionRootName { get; }

Name of the root element of a bare sequence of this type, or null when there is none

The DataContract profile names such a root by its ArrayOfX convention, in the namespace of . The General profile has no convention: a collection root requires an explicit name from the caller, and a here is what makes the entry points reject to guess one ().

ElementName

CrystalXmlName ElementName { get; }

Element name this type writes when the caller does not name it

The contract name, carrying the contract namespace on the DataContract profile and no namespace on the General one. This is the name a bare item of this type takes inside a collection root.

Methods

WriteXmlElement

void WriteXmlElement<TEmitter>(ref TEmitter emitter, in CrystalXmlName name, T value, CrystalXmlSettings? settings, int depth = 0)

Writes value as an element named name

  • emitter — Destination emitter, passed by ref per the ICrystalXmlEmitter contract
  • name — Name of the element to write; the caller owns the name, this serializer owns the content
  • value — Value to write, or null to write the empty element, marked nil when the settings ask for null members
  • settings — Optional settings controlling the output, passed through unchanged to nested serializers
  • depth — Number of elements already open above this one, counted against MaxDepth