# API reference

Public surface you will use in applications. Generated XML comments ship as `lib/SWIFTFramework.xml`.

## SWIFTFramework

### Licensing

```csharp
public class Licensing
{
    public static string RunTimeLicenseKey { get; set; }
    public static string GetLicensingPath();
}
```

Set `RunTimeLicenseKey` before constructing any `SwiftMessage`. See [licensing.md](licensing.md).

### SwiftParser

```csharp
public sealed class SwiftParser
{
    public SwiftParser();
    public static SwiftParser Instance { get; }

    public SwiftMessage GetMessage(string message, List<ValidationError> parseError, bool validate = true);
    public List<SwiftMessage> GetMessages(string messages, char messagesDelimiter, List<ValidationError> parseError, bool validate = true);

    public string GetMessageAsText(SwiftMessage message);
    public string GetMessageAsXml(SwiftMessage message);
    public string GetMessageAsXmlRaw(SwiftMessage message);
    public SwiftMessage GetMessageFromXml(string xml);
}
```

### SwiftMessage

```csharp
[LicenseProvider(typeof(EncryptedLicenseProvider))]
public class SwiftMessage : SwiftElement
{
    public SwiftMessage();
    public SwiftMessage(bool initBlocks);
    public SwiftMessage(SwiftMessage message);

    public SwiftBlock1 Block1 { get; set; }
    public SwiftBlock2 Block2 { get; set; }
    public SwiftBlock3 Block3 { get; set; }
    public SwiftBlock4 Block4 { get; set; }
    public SwiftBlock5 Block5 { get; set; }
    public List<SwiftBlockUser> UserBlocks { get; set; }

    public virtual string MessageType { get; }
    public string Content { get; }

    public virtual bool IsMTType(string type);
    public SwiftTag GetTagByName(string tagName);
    public SwiftTag GetTagByNumber(int tagNumber);

    public virtual bool Validate();
    public virtual bool Validate(List<ValidationError> errorList);

    public string ToXml();
    public string ToXmlRaw();
    public string ToXml(SwiftMessageExportType exportType);
}
```

Typed MT classes inherit `SwiftMessage` and add tag/sequence properties.

### Blocks

| Type | Role |
|---|---|
| `SwiftBlock1` | Basic header: `ApplicationIdentifier`, `ServiceIdentifier`, `LTAddress`, `SessionNumber`, `SequenceNumber` |
| `SwiftBlock2` | Application header base: `MessageType`, `MessagePriority` |
| `SwiftBlock2Input` | Outgoing: `DestinationAddress`, `DeliveryMonitoring`, `ObsolescencePeriod` |
| `SwiftBlock2Output` | Incoming: input time, MIR (`MessageInputReference`), output date/time |
| `SwiftBlock3` | User header (tag list) |
| `SwiftBlock4` | Text block (tag list) |
| `SwiftBlock5` | Trailer (tag list) |
| `SwiftBlockUser` | Extra blocks such as `{S:…}` |

Tag-list blocks (`3`, `4`, `5`, user) support `AddTag(SwiftTag)` and `Tags`.

### SwiftTag

```csharp
public class SwiftTag
{
    public SwiftTag();
    public SwiftTag(string inner);            // "20:VALUE"
    public SwiftTag(string name, string value);

    public string Name { get; set; }
    public string Value { get; set; }
}
```

### SwiftTagWrapper

Typed tag properties return wrappers (for example `Tag20`, `Tag32A`) that inherit `SwiftTagWrapper`. They expose `Value` plus parsed subfields (`Date`, `Amount`, `Currency`, …) when the tag format has them.

### Other model types

| Type | Role |
|---|---|
| `SwiftElement` | Base for messages, sequences, wrappers |
| `SwiftTagSequence` | A named sequence inside Block 4 |
| `MessageInputReference` | MIR inside Block 2 output |
| `UnparsedTextList` | Unparsed FIN leftovers |
| `SwiftMessageExportType` | `Structured`, `Raw`, `Biztalk` |

## SWIFTFramework.Validation

| Type | Role |
|---|---|
| `ValidationError` | `Type`, `Description`, `PropertyName`, `ParentPropertyObject` |
| `ValidationErrorType` | See [validation.md](validation.md) |
| `IValidate` / `IValidator` | Validator contracts |
| `ValidatePropertyBase` | Property validator base |
| `ValidateTagBase` | Tag validator base |
| `ValidationRuleBase` | Rule base (`Validate(string)`) |
| `ValidationRule_Length` | Length |
| `ValidationRule_Range` | Range |
| `ValidationRule_Enumeration` | Allowed values |
| `ValidationRule_RegEx` | Regular expression |

## SWIFTFramework.Messages.Category0 … Category9

One public class per MT / MTS type, named `MT103`, `MT202COV`, `MTS21_FIN_ACKNAK`, and so on. Full list: [message-types.md](message-types.md).

Each class lives in `SWIFTFramework.Messages.CategoryN` where `N` is the first digit of the MT number (`MT103` → `Category1`, `MT300` → `Category3`). Category 0 system messages use `Category0`.

## Exceptions

| Exception | When |
|---|---|
| `System.ComponentModel.LicenseException` | No / invalid / wrong-product license |
| `InvalidOperationException` | Structured XML export of a message that does not match its definition |
| `Exception` | `IsMTType` argument not length 3; some parse/definition failures |

## IntelliSense file

`lib/SWIFTFramework.xml` is the compiler-generated documentation file. Point IDEs at the same folder as the DLL to get member comments.
