Skip to main content
Version: 0.3.x (0.3.0)

Class ValueObjectXml

Namespace: AdCodicem.ValueObjects.Metadata
Assembly: AdCodicem.ValueObjects.Abstractions.dll

Reads, writes and describes a value object in XML, for the IXmlSerializable implementation the generator emits on the value objects of an assembly marked [assembly: ValueObjectXmlSerialization].

public static class ValueObjectXml

Inheritance​

object ← ValueObjectXml

Inherited Members​

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks​

A value object is written as the content of its element, in the form XmlSerializer writes its underlying type in, and read in the form XmlSerializer reads that type in, then through its rules: it reads every document written when the member was the primitive it replaces. A 128-bit integer, which XmlSerializer writes as an empty element, is written as its digits.

A refusal is an naming the type and the rule, never the text, which carries the code of the rule under : for an element marked xsi:nil, for text that is not of the underlying type, or an element holding elements, the code of the rule otherwise.

A value object written by hand implements IXmlSerializable through these methods too, as long as its underlying type is one the generator supports.

Methods​

ProvideSchema<TSelf, TValue>(XmlSchemaSet, string?)​

Adds the xs:simpleType describing a value object to a schema set, once, and names it.

public static XmlQualifiedName ProvideSchema<TSelf, TValue>(XmlSchemaSet schemas, string? xmlNamespace) where TSelf : struct, IValueObject<TSelf, TValue>

Parameters​

schemas XmlSchemaSet

The schema set an exporter or a serializer hands the schema provider.

xmlNamespace string?

The namespace of the type, or null for the one DataContractSerializer derives from its CLR namespace.

Returns​

XmlQualifiedName

The qualified name of the type.

Type Parameters​

TSelf

The value object.

TValue

Its underlying type.

Remarks​

The type restricts the XSD type of the underlying value with the rules of TSelf.Schema: the lengths as minLength and maxLength, the pattern as pattern when XSD can say what it means, the bounds as minInclusive and maxInclusive, the known values of a closed set as enumeration and the description as documentation. A facet System.Xml cannot read, such as a bound of a 128-bit integer beyond what a holds, is left out, since XmlSerializer would refuse the whole type for it.

The type is named after the value object, after the types it is nested in and joined to them with a dot, and, for a construction of a generic value object, followed by Of and the names of its type arguments. Its name leaves out the CLR namespace, which the default XML namespace carries: two value objects of one name put under one XML namespace share one type when their rules agree, and are refused when they differ, since the type would describe the second with the rules of the first.

Exceptions​

ArgumentNullException

schemas is null.

InvalidOperationException

The schema set holds a type of that name and namespace describing another value object, with other rules.

NotSupportedException

TValue is not an underlying type the generator supports.

Read<TSelf, TValue>(XmlReader)​

Reads the element the reader is positioned on as a value object: its text, in the lexical form of the underlying type, normalized and validated.

public static TSelf Read<TSelf, TValue>(XmlReader reader) where TSelf : struct, IValueObject<TSelf, TValue>

Parameters​

reader XmlReader

The reader, on the start tag of the element; past its end tag on return.

Returns​

TSelf

The value object.

Type Parameters​

TSelf

The value object.

TValue

Its underlying type.

Exceptions​

ArgumentNullException

reader is null.

XmlException

The element is marked xsi:nil, its text is not of the underlying type, or the type refuses it.

NotSupportedException

TValue is not an underlying type the generator supports.

Write<TSelf, TValue>(XmlWriter, TSelf)​

Writes a value object as the content of the current element, in the lexical form of its underlying type.

public static void Write<TSelf, TValue>(XmlWriter writer, TSelf value) where TSelf : struct, IValueObject<TSelf, TValue>

Parameters​

writer XmlWriter

The writer, inside the element.

value TSelf

The value object.

Type Parameters​

TSelf

The value object.

TValue

Its underlying type.

Exceptions​

ArgumentNullException

writer is null.

XmlException

The instance is the default, and its type refuses the default's value.

NotSupportedException

TValue is not an underlying type the generator supports.