# MailMerge.MergeObjects Method

> Merges a collection of type System.Collections.IEnumerable containing objects of any type or instances of type System.Collections.Generic.Dictionary with string keys into the loaded document template.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 20.0
- **Namespace:** `TXTextControl.DocumentServer`
- **Package:** `TXTextControl.TextControl.WinForms.SDK` (assembly `TXDocumentServer.dll`, from the private NuGet feed or Text Control Offline Packages)
- **.NET Framework:** reference `TXDocumentServer.dll` from the setup
- **Path:** TX Text Control .NET for Windows Forms > Reference > TXTextControl.DocumentServer > MailMerge.MergeObjects Method
- **952 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver/mailmerge/mergeobjects-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver/mailmerge/mergeobjects-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver/mailmerge/mergeobjects-method/llms-full.txt

---

### Description

Merges a collection of type `System.Collections.IEnumerable` containing objects of any type or instances of type `System.Collections.Generic.Dictionary` with string keys into the loaded document template.

### Syntax

#### MergeObjects(IEnumerable, bool)

Interprets all public properties of the objects or the key names of the dictionaries in the collection as possible table columns and / or child tables. The type of the first object (or the key names and types of the first dictionary) in the collection is analyzed via .NET reflection and used as the basis of the assumed table structure. (In case of the collection containing objects of different types, the merge process is successful nevertheless, but some fields will be empty.) Properties of simple data types (e. g. string, int, enum) are converted to text using the ToString method. The textual representation of enum values can be specified using the `System.ComponentModel.DescriptionAttribute`. (For example: enum FoodCategory { \[Description("Grains / Cereals")\] Grains\_Cereals, ... }.) The name by which Properties are mapped to field names can be adjusted using the `System.ComponentModel.DisplayNameAttribute`. (For example: \[DisplayName("Name")\] public string ProductName { get; set; }.) Complex properties which are themselves of type `System.Collections.IEnumerable` are interpreted as child Tables and used for merging merge blocks and nested merge blocks. This way data relations can be represented. Properties of a type itself having public properties are either interpreted as a simple table column (the merged text then is determined using the `ToString()` method) or they are treated as if they were a child table containing only one data row with the properties being the table columns. The second parameter specifies whether the single documents should be merged into one document or split into separate documents. The supported format of the merge fields can be found in the ASP.NET User's Guide.

```csharp
public void MergeObjects(IEnumerable mergeData, bool append);
```

```vbnet
Public Sub MergeObjects(mergeData As IEnumerable, append As Boolean)
```

| Parameter | Description |
|---|---|
| mergeData | Specifies a `System.Collections.IEnumerable` that contains the merge data. |
| append | Specifies whether the single documents should be merged into one document or split into separate documents. |

#### MergeObjects(IEnumerable)

Does the same as MergeObjects with the parameter “append” set to true.

```csharp
public void MergeObjects(IEnumerable mergeData);
```

```vbnet
Public Sub MergeObjects(mergeData As IEnumerable)
```

| Parameter | Description |
|---|---|
| mergeData | Specifies a `System.Collections.IEnumerable` that contains the merge data. |

### Examples

The following example uses Merge Objects in a focused Mail Merge workflow. The created object is then available to the surrounding document workflow.

```csharp
mailMerge.MergeObjects(new UserDefinedPropertyDictionary(), true);
Console.WriteLine("Mail Merge is ready for use.");
```

```vbnet
mailMerge.MergeObjects(New UserDefinedPropertyDictionary(), True)
Console.WriteLine("Mail Merge is ready for use.")
```

---

## Nearby

- **Previous:** [MailMerge.MergeObject Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver/mailmerge/mergeobject-method/llms-full.txt)
- **Next:** [MailMerge.Print Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver/mailmerge/print-method/llms-full.txt)
