# Creating messages from code

## Construct the typed class

```csharp
var mt103 = new MT103();           // initializes blocks and mandatory tags
var copy = new MT103(existing);    // copy constructor from a SwiftMessage
```

Calling `new MT103()` requires a valid license (same as parse).

## Property naming

Each field is exposed twice:

| Style | Example |
|---|---|
| Semantic + tag | `SendersReference_20` |
| Tag + semantic | `Tag20_SendersReference` |

Both return the same wrapper. Use either; do not treat them as independent storage.

Repeating tags are arrays. Add another occurrence with the generated `Add…` method:

```csharp
mt202.SequenceA.AddTimeIndication_A_13C().Value = "/FROTIME/1030+0100";
```

Sequences are nested objects:

```csharp
mt202cov.SequenceA.TransactionReferenceNumber_A_20.Value = "REF123";
mt202cov.SequenceA.ValueDateCurrencyCodeAmount_A_32A.Amount = 1000.33m;
```

COV variants automatically emit `{119:COV}` in Block 3 when written.

## Headers (Block 1 and 2)

```csharp
mt103.Block1.ApplicationIdentifier = "F";   // F, A, L
mt103.Block1.ServiceIdentifier = "01";
mt103.Block1.LTAddress = "BANKUSPPAXXX";    // 12 characters
mt103.Block1.SessionNumber = "0000";
mt103.Block1.SequenceNumber = "000000";

mt103.Block2.MessageType = "103";
mt103.Block2.MessagePriority = "N";         // S, U, N

var input = (SwiftBlock2Input)mt103.Block2;
input.DestinationAddress = "BANKUKZHAXXX";
```

Typed constructors set `MessageType` from the class (an `MT103` reports `"103"`).

For a received/output header use `SwiftBlock2Output` (input time, MIR, output date/time).

## Block 3 (optional user header)

```csharp
mt103.Block3.AddTag(new SwiftTag("108", "1111112222222"));
mt103.Block3.AddTag(new SwiftTag("103", "USD"));
```

`SwiftTag` constructors:

```csharp
new SwiftTag();
new SwiftTag("20:ABCDEREF");      // name + value in one string
new SwiftTag("20", "ABCDEREF");   // name, value
```

## Typed tag subfields

Composite tags expose parsed parts. Example `32A` (`yyMMdd` + currency + amount):

```csharp
mt103.ValueDateCurrencyInterbankSettledAmount_32A.Date = new DateTime(2026, 7, 24);
mt103.ValueDateCurrencyInterbankSettledAmount_32A.Currency = "USD";
mt103.ValueDateCurrencyInterbankSettledAmount_32A.Amount = 14551.00m;
```

Or set the raw SWIFT value:

```csharp
mt103.ValueDateCurrencyInterbankSettledAmount_32A.Value = "260724USD14551,";
```

## Multiline party tags

```csharp
mt103.OrderingCustomer_50K.Value = "/0123456789\r\nACME CORP\r\nNEW YORK";
mt103.BeneficiaryCustomer_59.Value = "/9988776655\r\nJOHN DOE";
```

Choice tags (`50A` / `50F` / `50K`, `59` / `59A`, …) are separate properties. Setting one does not clear the others automatically — populate the option you intend to emit.

## Generic Block 4 construction

You can also build an untyped `SwiftMessage` and add tags:

```csharp
var message = new SwiftMessage();
message.Block1 = new SwiftBlock1(message, "F", "01", "BANKABCDXXXX", "1234", "123456");
message.Block2 = new SwiftBlock2Output(message, "103", "0805", "090112",
    "ABCDEFGHIJKL", "1234", "123456", "090112", "0805", "N");
message.Block4 = new SwiftBlock4(message);
message.Block4.AddTag(new SwiftTag("20", "ABCDEFGHIJKLMNOP"));
message.Block4.AddTag(new SwiftTag("23B", "CRED"));
```

Prefer the typed MT class when you know the type — it creates mandatory tags and validates against the official definition.

## Emit

```csharp
string fin = SwiftParser.Instance.GetMessageAsText(mt103);
string xml = mt103.ToXml();
```
