> ## Documentation Index
> Fetch the complete documentation index at: https://easyaf.nimbleapps.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# XmlTypeInfo

> Provides XML serialization-related metadata about a type.

## Definition

**Assembly:** CloudNimble.XmlEssentials.dll

**Namespace:** CloudNimble.Text.Xml.Serialization

**Inheritance:** CloudNimble.Text.Xml.Serialization.XmlTypeInfo

## Syntax

```csharp theme={"dark"}
CloudNimble.Text.Xml.Serialization.XmlTypeInfo<T>
```

## Summary

Provides XML serialization-related metadata about a type.

## Usage

An `XmlTypeInfo` 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)`, or `TryGetTypeInfo`.

Pass it to an `XmlSerializer` overload. These overloads use no reflection, so they're safe in trimmed and Native AOT applications:

```csharp theme={"dark"}
string xml = XmlSerializer.Serialize(order, OrderXmlContext.Default.Order);

Order? copy = XmlSerializer.Deserialize(xml, OrderXmlContext.Default.Order);
```

The classes correspond to `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 of `Order` 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.

```csharp theme={"dark"}
XmlTypeInfo<Order> metadata = MetadataOrderXmlContext.Default.Order;

output.WriteLine($"Root element: {metadata.RootName.LocalName}");
foreach (XmlPropertyInfo property in metadata.Properties)
{
    string kind = property.IsAttribute ? "attribute" : "element";
    output.WriteLine($"{property.Name.LocalName}: {kind}, {property.PropertyType.Type.Name}");
}
```

```csharp theme={"dark"}
public sealed class Order
{
    public string? Customer { get; set; }

    [XmlAttribute]
    public int Id { get; set; }

    [XmlElement("Line")]
    public List<OrderLine> Lines { get; set; } = [];
}
```

The code produces the following output:

```text theme={"dark"}
Root element: Order
Id: attribute, Int32
Customer: element, String
Line: element, List`1
```

[View the complete sample on GitHub](https://github.com/CloudNimble/XmlEssentials/blob/main/src/CloudNimble.XmlEssentials.Samples/33_SourceGenerationModes.cs)

## 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.
* **`Properties` lists 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 in `Metadata` mode, lists one `XmlPropertyInfo` for each member in the order they're written. Type info for a simple value, for a custom converter, or from a context in `Serialization` mode has an empty list.
* **`CreateObject` is `null` unless the type is mapped as an object and is created with no arguments.** It's `null` for a type that is created through a constructor with parameters, and for type info from a context in `Serialization` mode.
* **Type info is bound to its `Options`.** The serializer uses those options when you pass the type info, whatever other options exist. Type info from `XmlSerializerOptions.GetTypeInfo` is 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

### &#x20;.ctor Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Creates type info.

#### Syntax

```csharp theme={"dark"}
private protected XmlTypeInfo(System.Type type, CloudNimble.Text.Xml.Serialization.XmlConverter converter, CloudNimble.Text.Xml.XmlSerializerOptions options, CloudNimble.Text.Xml.XmlName rootName, bool isNillable)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `type` | `System.Type` | The CLR type. |
| `converter` | `CloudNimble.Text.Xml.Serialization.XmlConverter` | The converter. |
| `options` | `CloudNimble.Text.Xml.XmlSerializerOptions` | The serializer options. |
| `rootName` | `CloudNimble.Text.Xml.XmlName` | The document element name. |
| `isNillable` | `bool` | Whether null is representable. |

### &#x20;.ctor Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public Object()
```

## Properties

### &#x20;Converter

Gets the converter that reads and writes values of type *T*.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.Serialization.XmlConverter<T> Converter { get; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.Serialization.XmlConverter<T>`
The converter associated with the type.

### &#x20;Converter Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Gets the [XmlConverter](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlConverter.md) associated with the current type.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.Serialization.XmlConverter Converter { get; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.Serialization.XmlConverter`
The converter that reads and writes values of [XmlTypeInfo.Type](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md#type).

### &#x20;CreateObject Inherited Virtual

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Gets a parameterless factory that creates an instance of [XmlTypeInfo.Type](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md#type) on deserialization.

#### Syntax

```csharp theme={"dark"}
public virtual System.Func<object> CreateObject { get; }
```

#### Property Value

Type: `System.Func<object>?`
A factory that creates an instance of [XmlTypeInfo.Type](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md#type), or [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) if the type is not mapped as an
object or is created through a constructor that has parameters.

### &#x20;IsNillable Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Gets a value that indicates whether a value of [XmlTypeInfo.Type](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md#type) can be [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

#### Syntax

```csharp theme={"dark"}
public bool IsNillable { get; }
```

#### Property Value

Type: `bool`
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if [XmlTypeInfo.Type](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md#type) is a reference type or a [Nullable`1](https://learn.microsoft.com/dotnet/api/system.nullable-1); otherwise, [`false\`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

#### Remarks

Only a nillable type can be read from an element marked `xsi:nil="true"` or written from a [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) value.
A [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) value that is written is an element marked `xsi:nil="true"`.

### &#x20;Options Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Gets the [XmlSerializerOptions](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md) value associated with the current [XmlTypeInfo](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md) instance.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.XmlSerializerOptions Options { get; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlSerializerOptions`
The options that the metadata was created for.

### &#x20;Properties Inherited Virtual

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Gets the list of [XmlPropertyInfo](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlPropertyInfo.md) metadata corresponding to the current type.

#### Syntax

```csharp theme={"dark"}
public virtual System.Collections.Generic.IList<CloudNimble.Text.Xml.Serialization.XmlPropertyInfo> Properties { get; }
```

#### 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](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlSourceGenerationMode.md) mode.

### &#x20;ResumableBinding Inherited Virtual

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Gets the binding of an object that the built-in object converter reads, which is what a read from a
stream can stop in the middle of and go on with; otherwise [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

#### Syntax

```csharp theme={"dark"}
internal virtual CloudNimble.Text.Xml.Serialization.XmlObjectBinding ResumableBinding { get; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.Serialization.XmlObjectBinding?`

### &#x20;RootLeafCloseTag Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Gets the whole end tag of the element named for [XmlTypeInfo.Type](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md#type), `</name>`, or null
when the name has a namespace or is not a short ASCII name.

#### Syntax

```csharp theme={"dark"}
internal byte[] RootLeafCloseTag { get; }
```

#### Property Value

Type: `byte[]?`

### &#x20;RootLeafOpenTag Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Gets the whole start tag of the element named for [XmlTypeInfo.Type](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md#type), `<name>`, or null
when the name has a namespace or is not a short ASCII name.

#### Syntax

```csharp theme={"dark"}
internal byte[] RootLeafOpenTag { get; }
```

#### Property Value

Type: `byte[]?`

### &#x20;RootName Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Gets the name of the document element that a value of [XmlTypeInfo.Type](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md#type) is serialized as.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.XmlName RootName { get; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlName`
The name of the document element.

### &#x20;SequenceElementName Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Gets the UTF-8 name of the element that holds a sequence of values of [XmlTypeInfo.Type](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md#type). It is found
through the attributes of the type, so it is found once and kept.

#### Syntax

```csharp theme={"dark"}
internal byte[] SequenceElementName { get; }
```

#### Property Value

Type: `byte[]`

### &#x20;Type Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Gets the [Type](https://learn.microsoft.com/dotnet/api/system.type) for which the XML serialization contract is defined.

#### Syntax

```csharp theme={"dark"}
public System.Type Type { get; }
```

#### Property Value

Type: `System.Type`
The type that the metadata describes.

## Methods

### &#x20;CheckRoot Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Checks that the start tag *reader* is on is the document element
of [XmlTypeInfo.Type](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md#type).

#### Syntax

```csharp theme={"dark"}
internal void CheckRoot(ref CloudNimble.Text.Xml.Utf8XmlReader reader)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `reader` | `CloudNimble.Text.Xml.Utf8XmlReader` | The reader. |

### &#x20;CreateRootName Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Builds the document element name of *type*.

#### Syntax

```csharp theme={"dark"}
internal static CloudNimble.Text.Xml.XmlName CreateRootName(System.Type type, CloudNimble.Text.Xml.XmlSerializerOptions options)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `type` | `System.Type` | The CLR type. |
| `options` | `CloudNimble.Text.Xml.XmlSerializerOptions` | The serializer options. |

#### Returns

Type: `CloudNimble.Text.Xml.XmlName`
The local name from [XmlRootAttribute.ElementName](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlRootAttribute.md#elementname), or the XML name of the type under the
element naming policy when the attribute gives none; in the namespace from
[XmlRootAttribute.Namespace](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlRootAttribute.md#namespace), or [XmlSerializerOptions.DefaultNamespace](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#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.

### &#x20;Equals Inherited Virtual

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public virtual bool Equals(object obj)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `obj` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;Equals Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public static bool Equals(object objA, object objB)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `objA` | `object?` | - |
| `objB` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;GetHashCode Inherited Virtual

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public virtual int GetHashCode()
```

#### Returns

Type: `int`

### &#x20;GetType Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public System.Type GetType()
```

#### Returns

Type: `System.Type`

### &#x20;IsNilElement Inherited Abstract

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Returns whether the start tag the reader is on is marked `xsi:nil`, so that the value is null.

#### Syntax

```csharp theme={"dark"}
internal abstract bool IsNilElement(ref CloudNimble.Text.Xml.Utf8XmlReader reader)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `reader` | `CloudNimble.Text.Xml.Utf8XmlReader` | The reader, on a start tag. |

#### Returns

Type: `bool`
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) when the element stands for null.

#### Exceptions

| Exception | Description |
| - | - |
| `XmlException` | The element is marked nil and the type cannot be null. |

### &#x20;MemberwiseClone Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
protected internal object MemberwiseClone()
```

#### Returns

Type: `object`

### &#x20;ReadElementAsObject Inherited Abstract

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Reads the element the reader is on, whatever its name, and returns the value boxed.

#### Syntax

```csharp theme={"dark"}
internal abstract object ReadElementAsObject(ref CloudNimble.Text.Xml.Utf8XmlReader reader)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `reader` | `CloudNimble.Text.Xml.Utf8XmlReader` | The reader, on a start tag. |

#### Returns

Type: `object?`
The value.

### &#x20;ReadRootAsObject Inherited Abstract

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Reads the document element of [XmlTypeInfo.Type](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md#type) and returns the value boxed.

#### Syntax

```csharp theme={"dark"}
internal abstract object ReadRootAsObject(ref CloudNimble.Text.Xml.Utf8XmlReader reader)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `reader` | `CloudNimble.Text.Xml.Utf8XmlReader` | The reader. |

#### Returns

Type: `object?`
The value.

### &#x20;ReferenceEquals Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public static bool ReferenceEquals(object objA, object objB)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `objA` | `object?` | - |
| `objB` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;RootLeafTags Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Gets the tags of the element named for [XmlTypeInfo.Type](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md#type), built ahead of time, for a value that is
written without an element frame.

#### Syntax

```csharp theme={"dark"}
internal byte[] RootLeafTags(CloudNimble.Text.Xml.Utf8XmlWriter writer, out byte[] closeTag)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `writer` | `CloudNimble.Text.Xml.Utf8XmlWriter` | The writer. |
| `closeTag` | `byte[]?` | The whole end tag, `</name>`. |

#### 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.

### &#x20;ToString Inherited Virtual

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public virtual string ToString()
```

#### Returns

Type: `string?`

### &#x20;TryWriteStartDocumentElement Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Starts an element as the document element of [XmlTypeInfo.Type](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md#type), with the namespaces of
[XmlSerializerOptions.Namespaces](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#namespaces) and of the type's
[XmlNamespaceDeclarationAttribute](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlNamespaceDeclarationAttribute.md)s declared on it, when there are any and the writer is
at the document level.

#### Syntax

```csharp theme={"dark"}
internal bool TryWriteStartDocumentElement(CloudNimble.Text.Xml.Utf8XmlWriter writer, System.ReadOnlySpan<byte> utf8LocalName, System.ReadOnlySpan<byte> utf8NamespaceUri)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `writer` | `CloudNimble.Text.Xml.Utf8XmlWriter` | The writer. |
| `utf8LocalName` | `System.ReadOnlySpan<byte>` | The local name of the element. |
| `utf8NamespaceUri` | `System.ReadOnlySpan<byte>` | The namespace of the element, or empty. |

#### Returns

Type: `bool`
[`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) when nothing was written, and the caller starts the element itself.

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The declared namespaces cannot be written on the element. |

#### 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.

### &#x20;WriteContentAsObject Inherited Abstract

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Writes a boxed value as element or attribute content, without a wrapping start tag.

#### Syntax

```csharp theme={"dark"}
internal abstract void WriteContentAsObject(CloudNimble.Text.Xml.Utf8XmlWriter writer, object value)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `writer` | `CloudNimble.Text.Xml.Utf8XmlWriter` | The writer. |
| `value` | `object` | The value. |

### &#x20;WriteNullRoot Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Writes a null value as the document element.

#### Syntax

```csharp theme={"dark"}
internal void WriteNullRoot(CloudNimble.Text.Xml.Utf8XmlWriter writer)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `writer` | `CloudNimble.Text.Xml.Utf8XmlWriter` | The writer. |

### &#x20;WriteRootAsObject Inherited Abstract

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Writes a boxed value as the document element.

#### Syntax

```csharp theme={"dark"}
internal abstract void WriteRootAsObject(CloudNimble.Text.Xml.Utf8XmlWriter writer, object value)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `writer` | `CloudNimble.Text.Xml.Utf8XmlWriter` | The writer. |
| `value` | `object?` | The value. |

### &#x20;WriteStartRoot Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Writes the start tag of the element named for [XmlTypeInfo.Type](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md#type), declaring its namespace when it has
one. When it is the document element, the namespaces of
[XmlSerializerOptions.Namespaces](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#namespaces) and of the type's
[XmlNamespaceDeclarationAttribute](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlNamespaceDeclarationAttribute.md)s are declared on it.

#### Syntax

```csharp theme={"dark"}
internal void WriteStartRoot(CloudNimble.Text.Xml.Utf8XmlWriter writer)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `writer` | `CloudNimble.Text.Xml.Utf8XmlWriter` | The writer. |

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The declared namespaces cannot be written on the document element. |

### &#x20;WriteStartRoot Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Serialization.XmlTypeInfo`

Writes the start tag of an element in the namespace of [XmlTypeInfo.Type](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlTypeInfo.md#type) under another local name:
the element that holds a sequence of values of the type.

#### Syntax

```csharp theme={"dark"}
internal void WriteStartRoot(CloudNimble.Text.Xml.Utf8XmlWriter writer, System.ReadOnlySpan<byte> utf8LocalName)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `writer` | `CloudNimble.Text.Xml.Utf8XmlWriter` | The writer. |
| `utf8LocalName` | `System.ReadOnlySpan<byte>` | The local name of the element. |

#### Exceptions

| Exception | Description |
| - | - |
| `InvalidOperationException` | The declared namespaces cannot be written on the document element. |

## 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


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.