Definition
Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml.Serialization Inheritance: CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Summary
Provides XML serialization-related metadata about a type.Usage
AnXmlTypeInfo is the serializer’s contract for one type: the converter that reads and writes it, the name of its document element, and the options it was built for. XmlTypeInfo<T> is the typed form you pass to XmlSerializer.
You don’t create type info. You get it from one of two places:
- A property of a source-generated context, such as
OrderXmlContext.Default.Order. - An options instance that has a resolver, with
XmlSerializerOptions.GetTypeInfo<T>(),GetTypeInfo(Type), orTryGetTypeInfo.
XmlSerializer overload. These overloads use no reflection, so they’re safe in trimmed and Native AOT applications:
JsonTypeInfo and JsonTypeInfo<T> in System.Text.Json.
Remarks
Instances are created by the library. This class cannot be derived from outside the library.Type Parameters
T- The type that the metadata describes.
Examples
Read the contract of a type
The following example lists the members ofOrder as the serializer maps them. The type info comes from a source-generated context, which builds it from generated metadata. A context in the default mode gives the same list.
Considerations
- Type info is read-only. Every property has a getter only. Unlike
JsonTypeInfo, you can’t add, remove, or change members to customize a contract. Change the mapping with attributes, options, or a custom converter. - You can’t derive from it or construct it. The constructors aren’t accessible outside the library.
Propertieslists the members of a type mapped as an object. Type info from the reflection resolver, or from a source-generated context in the default mode or inMetadatamode, lists oneXmlPropertyInfofor each member in the order they’re written. Type info for a simple value, for a custom converter, or from a context inSerializationmode has an empty list.CreateObjectisnullunless the type is mapped as an object and is created with no arguments. It’snullfor a type that is created through a constructor with parameters, and for type info from a context inSerializationmode.- Type info is bound to its
Options. The serializer uses those options when you pass the type info, whatever other options exist. Type info fromXmlSerializerOptions.GetTypeInfois cached on that instance, and asking for it makes the instance read-only. - It’s safe to share. Keep and reuse type info across threads, as you would the options or the context it came from.
Constructors
.ctor Inherited
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Parameters
.ctor Inherited
Inherited from
objectSyntax
Properties
Converter
Gets the converter that reads and writes values of type T.Syntax
Property Value
Type:CloudNimble.Text.Xml.Serialization.XmlConverter<T>
The converter associated with the type.
Converter Inherited
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Property Value
Type:CloudNimble.Text.Xml.Serialization.XmlConverter
The converter that reads and writes values of XmlTypeInfo.Type.
CreateObject Inherited Virtual
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Property Value
Type:System.Func<object>?
A factory that creates an instance of XmlTypeInfo.Type, or null if the type is not mapped as an
object or is created through a constructor that has parameters.
IsNillable Inherited
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfonull.
Syntax
Property Value
Type:bool
true if XmlTypeInfo.Type is a reference type or a Nullable1](https://learn.microsoft.com/dotnet/api/system.nullable-1); otherwise, [false`.
Remarks
Only a nillable type can be read from an element markedxsi:nil="true" or written from a null value.
A null value that is written is an element marked xsi:nil="true".
Options Inherited
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Property Value
Type:CloudNimble.Text.Xml.XmlSerializerOptions
The options that the metadata was created for.
Properties Inherited Virtual
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Property Value
Type:System.Collections.Generic.IList<CloudNimble.Text.Xml.Serialization.XmlPropertyInfo>
The serialized members of an object type, in the order they are written. The list is empty for a type that is not mapped as an object,
and for a type that a context generated in XmlSourceGenerationMode.Serialization mode.
ResumableBinding Inherited Virtual
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfonull.
Syntax
Property Value
Type:CloudNimble.Text.Xml.Serialization.XmlObjectBinding?
RootLeafCloseTag Inherited
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfo</name>, or null
when the name has a namespace or is not a short ASCII name.
Syntax
Property Value
Type:byte[]?
RootLeafOpenTag Inherited
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfo<name>, or null
when the name has a namespace or is not a short ASCII name.
Syntax
Property Value
Type:byte[]?
RootName Inherited
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Property Value
Type:CloudNimble.Text.Xml.XmlName
The name of the document element.
SequenceElementName Inherited
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Property Value
Type:byte[]
Type Inherited
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Property Value
Type:System.Type
The type that the metadata describes.
Methods
CheckRoot Inherited
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Parameters
CreateRootName Inherited
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Parameters
Returns
Type:CloudNimble.Text.Xml.XmlName
The local name from XmlRootAttribute.ElementName, or the XML name of the type under the
element naming policy when the attribute gives none; in the namespace from
XmlRootAttribute.Namespace, or XmlSerializerOptions.DefaultNamespace when
the attribute gives none.
Remarks
Every kind of type info uses this one rule, so a type has the same document element whether the reflection resolver, a generated context, or a converter of the caller’s reads and writes it.Equals Inherited Virtual
Inherited from
objectSyntax
Parameters
Returns
Type:bool
Equals Inherited
Inherited from
objectSyntax
Parameters
Returns
Type:bool
GetHashCode Inherited Virtual
Inherited from
objectSyntax
Returns
Type:int
GetType Inherited
Inherited from
objectSyntax
Returns
Type:System.Type
IsNilElement Inherited Abstract
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoxsi:nil, so that the value is null.
Syntax
Parameters
Returns
Type:bool
true when the element stands for null.
Exceptions
MemberwiseClone Inherited
Inherited from
objectSyntax
Returns
Type:object
ReadElementAsObject Inherited Abstract
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Parameters
Returns
Type:object?
The value.
ReadRootAsObject Inherited Abstract
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Parameters
Returns
Type:object?
The value.
ReferenceEquals Inherited
Inherited from
objectSyntax
Parameters
Returns
Type:bool
RootLeafTags Inherited
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Parameters
Returns
Type:byte[]?
The whole start tag, <name>, or null when the writer is not inside an element or the
name cannot be written from bytes built ahead of time.
Remarks
For an item of a collection that is the document root. The caller writes exactly one value.ToString Inherited Virtual
Inherited from
objectSyntax
Returns
Type:string?
TryWriteStartDocumentElement Inherited
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Parameters
Returns
Type:bool
false when nothing was written, and the caller starts the element itself.
Exceptions
Remarks
The name is a parameter because a document element is not always named for the type: a value of a derived type is written under the derived type’s name, and a sequence under a name of its own.WriteContentAsObject Inherited Abstract
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Parameters
WriteNullRoot Inherited
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Parameters
WriteRootAsObject Inherited Abstract
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Parameters
WriteStartRoot Inherited
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Parameters
Exceptions
WriteStartRoot Inherited
Inherited from
CloudNimble.Text.Xml.Serialization.XmlTypeInfoSyntax
Parameters
Exceptions
Related APIs
- CloudNimble.Text.Xml.Serialization.XmlPropertyInfo
- CloudNimble.Text.Xml.Serialization.XmlSerializerContext
- CloudNimble.Text.Xml.Serialization.IXmlTypeInfoResolver
- CloudNimble.Text.Xml.Serialization.DefaultXmlTypeInfoResolver
- CloudNimble.Text.Xml.Serialization.XmlConverter
- CloudNimble.Text.Xml.XmlSerializer
- CloudNimble.Text.Xml.XmlSerializerOptions
- CloudNimble.Text.Xml.XmlName