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

# XmlObjectCreationHandling

> Determines how [XmlSerializer](/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializer) handles a member that already holds a value when it is deserialized.

## Definition

**Assembly:** CloudNimble.XmlEssentials.dll

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

**Inheritance:** System.Enum

## Syntax

```csharp theme={"dark"}
CloudNimble.Text.Xml.Serialization.XmlObjectCreationHandling
```

## Summary

Determines how [XmlSerializer](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializer.md) handles a member that already holds a value when it is deserialized.

## Usage

`XmlObjectCreationHandling` says what happens to the value a member already holds when the member is read. Use it in two places: [`[XmlObjectCreationHandling]`](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/Text/Xml/Serialization/XmlObjectCreationHandlingAttribute), for one member or one type, and `XmlSerializerOptions.PreferredObjectCreationHandling`, for every member. It is the counterpart of `JsonObjectCreationHandling`, with the same values and rules.

| Value | When the member is read |
| - | - |
| `Replace` | The member is given a new value. A member with no setter isn't read. This is the default. |
| `Populate` | The value the member holds is kept. Items are added to a collection, entries to a dictionary, and the members of an object are set on it. |

```csharp theme={"dark"}
var options = new XmlSerializerOptions
{
    PreferredObjectCreationHandling = XmlObjectCreationHandling.Populate,
};
```

See [Populate a collection that already holds a value](https://easyaf.nimbleapps.cloud/xmlessentials/guides/collections.md#populate-a-collection-that-already-holds-a-value) for what can and can't be populated.

## Remarks

The values and their meaning are those of `System.Text.Json.Serialization.JsonObjectCreationHandling`.

## Values

| Name | Value | Description |
| - | - | - |
| `Replace` | 0 | A new instance is created and assigned to the member. A member with no setter is not read. |
| `Populate` | 1 | The instance the member holds is populated: items are added to a collection, entries to a dictionary, and |
| the members of an object are set on it. A member that holds [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) is given a new instance | | |
| when it has a setter. | | |

## Related APIs

* System.IComparable
* System.ISpanFormattable
* System.IFormattable
* System.IConvertible


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