Class SwiftField
Collects all the information about a single SWIFT field.
Inherited Members
Namespace: Subsembly.Swift
Assembly: Subsembly.Sepa.dll
Syntax
public class SwiftField
Constructors
SwiftField()
Constructs an uninitialized (null) instance of a SwiftField.
Declaration
public SwiftField()
SwiftField(SwiftFieldType)
Constructs an empty SWIFT field of the given type.
Declaration
public SwiftField(SwiftFieldType nFieldType)
Parameters
Type | Name | Description |
---|---|---|
SwiftFieldType | nFieldType | Field type. |
SwiftField(String, SwiftBalance)
Declaration
public SwiftField(string sTag, SwiftBalance aBalance)
Parameters
Type | Name | Description |
---|---|---|
System.String | sTag | |
SwiftBalance | aBalance |
SwiftField(String, String)
Constructs a non-generic SWIFT field with the given Tag and Content.
Declaration
public SwiftField(string sTag, string sContent)
Parameters
Type | Name | Description |
---|---|---|
System.String | sTag | Field tag. This must not be null and must conform to the SWIFT field tag requirements. |
System.String | sContent | Field content. This must not be null. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | One of the arguments was null. |
System.ArgumentOutOfRangeException | The given Tag was not a valid SWIFT tag. |
SwiftField(String, String, String)
Constructs a generic SWIFT field with the given Tag, Qualifier and Content.
Declaration
public SwiftField(string sTag, string sQualifier, string sContent)
Parameters
Type | Name | Description |
---|---|---|
System.String | sTag | Field tag. This must not be null and must conform to the SWIFT field tag requirements. |
System.String | sQualifier | Must be a four character Qualifier. Must not be null. |
System.String | sContent | Field content. This must not be null. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | One of the arguments was null. |
System.ArgumentOutOfRangeException | The given Tag was not a valid SWIFT tag, or the given Qualifier was not a valid SWIFT generic field Qualifier. |
Properties
Content
The Content of a SWIFT field.
Declaration
public string Content { get; set; }
Property Value
Type | Description |
---|---|
System.String | With the exception of the EndOfText marker, all SWIFT fields have Content. |
Remarks
With the content string a CRLF-Sequence is represented as a single '\n' character. The '\n' is converted to/from a proper CRLF-Sequence when the field is read or written.
ContentLength
The length of the Content of this SWIFT field.
Declaration
public int ContentLength { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
DataSourceScheme
The Data Source Scheme (DSS) also known as the Issuer Code of a generic SWIFT field.
Declaration
public string DataSourceScheme { get; set; }
Property Value
Type | Description |
---|---|
System.String | Only a generic SWIFT field may have an optional DSS with a length of up to eight character. A non-generic SWIFT field never has one. The DSS can consist of upper case letters and digits only. For a generic field, the required Qualifier must always be set before the DSS is set. The FieldType is automatically changed to GenericField. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | When an invalid DSS is set, then an ArgumentOutOfRangeException is thrown. |
FieldType
The type of this SWIFT field.
Declaration
public SwiftFieldType FieldType { get; set; }
Property Value
Type | Description |
---|---|
SwiftFieldType |
Line
Optional line number where this SWIFT field starts in the surrounding SWIFT message or stream.
Declaration
public int Line { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | Processing a SWIFT stream begins with the line number one. While the stream is read, the line number is incremented by every CRLF sequence, including '@@' sequences, if those are permitted. As all SWIFT messages should start with a CRLF right away, the very first SWIFT field already begins at line two. The value zero indicates that the line number is not known. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | An attempt was made to set a negative value. |
Qualifier
The Qualifier of a generic SWIFT field.
Declaration
public string Qualifier { get; set; }
Property Value
Type | Description |
---|---|
System.String | A generic SWIFT field must always have a four character Qualifier, a non-generic SWIFT field never has one. The Qualifier can consist of upper case letters and digits only. If a Qualifier is set, the the FieldType is automatically changed to GenericField. If the Qualifier is set to null, then the DataSourceScheme is also set to null and the FieldType is automatically changed to NonGenericField. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | When an invalid Qualifier is set, then an ArgumentOutOfRangeException is thrown. |
Tag
The Tag of this SWIFT field.
Declaration
public string Tag { get; set; }
Property Value
Type | Description |
---|---|
System.String | A SWIFT field consists of two digits followed by an optional upper case option letter. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | When an invalid SWIFT field tag is set, then an ArgumentOutOfRangeException is thrown. |
Methods
ExtractCode(Int32, SwiftCharsets, Boolean)
Declaration
public string ExtractCode(int nLength, SwiftCharsets nCharset, bool fOptional)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | nLength | |
SwiftCharsets | nCharset | |
System.Boolean | fOptional |
Returns
Type | Description |
---|---|
System.String |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | |
SwiftException |
ExtractRestart()
Declaration
public void ExtractRestart()
ExtractSubfield(Int32, SwiftCharsets, SwiftSubfieldFlags)
Extracts the next generic subfield from the Content of this field.
Declaration
public string ExtractSubfield(int nLength, SwiftCharsets nCharset, SwiftSubfieldFlags nFlags = SwiftSubfieldFlags.None)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | nLength | The |
SwiftCharsets | nCharset | |
SwiftSubfieldFlags | nFlags | Indicates whether the subfield is Optional, and/or has a FixedLength. Other SwiftSubfieldFlags are not allowed. |
Returns
Type | Description |
---|---|
System.String | If a non-empty subfield content was extracted, then it is returned as a non-empty
string. If an immediate subfield delimiter was found, then an empty string is
returned. If no characters could be collected, because the end of the content has
already been reached, then |
Remarks
Generic subfields are always delimited by a single slash, or by the end of the content.
After all subfields have been extracted, any further calls will return null
.
In order to restart extracting subfields from the start of the content, the method
ExtractRestart() must be called.
Exceptions
Type | Condition |
---|---|
System.ArgumentException | |
SwiftException | If a valid subfield cannot be extracted as required, then a SwiftException with code MalformedFieldContent is thrown. This includes the case where a mandatory subfield is not present. |
ParseBalance()
Parses the Content of this SwiftField as a SWIFT balance.
Declaration
public SwiftBalance ParseBalance()
Returns
Type | Description |
---|---|
SwiftBalance | A new SwiftBalance instance with the details of the parsed balance. |
Remarks
Many SWIFT fields are defined to carry balance information. Most of these fields have all the same structure which is:
1!a6!n3!a15d
(D/C Mark) (Date) (Currency) (Amount)
A Debit/Credit Mark, followed by a date in the format YYMMDD, followed by a three letter currency code and finally the actual decimal amount.
This method attempts to interpret the Content of this SwiftField according to this structure and creates a new SwiftBalance instance that contains all the values from this balance.
Exceptions
Type | Condition |
---|---|
SwiftException | Thrown if the field content is not according to the expected balance structure. The
exception code will be MalformedFieldContent
and |
Subfield(Int32)
Extracts a subfield from the Content of this SwiftField.
Declaration
public string Subfield(int nIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | nIndex | The index of the subfield to be extracted. |
Returns
Type | Description |
---|---|
System.String | Returns the requested subfield, or an empty string, if the subfield does not exist.
If the Content is |
Remarks
This method assumes that the subfields are all delimited by slash characters.
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | The parameter nIndex was negative. |
Subfield(ref Int32, Int32, SwiftCharsets, SwiftSubfieldFlags)
Extracts a subfield from the Content of this SwiftField.
Declaration
public string Subfield(ref int nIndex, int nLength, SwiftCharsets nCharset, SwiftSubfieldFlags nFlags)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | nIndex | Zero-based character index where the subfield starts inside the
Content. Must not be negative. If the start index is already larger
than the total size of the Content, then nothing is extracted, i.e.
|
System.Int32 | nLength | The maximum number of characters that are extracted for the requested subfield. This must be at least 1. It can be as large as possible. Passing Int32.MaxValue generally extracts until the end of the Content. |
SwiftCharsets | nCharset | The SWIFT character set of the subfield to be extracted. Extraction stops at the first character that does not belong to this character set. |
SwiftSubfieldFlags | nFlags | A combination of flags that controls the subfield extraction. See the documentation of the SwiftSubfieldFlags enumeration for possible flags and their impact. |
Returns
Type | Description |
---|---|
System.String | If a nonempty subfield was extracted, then it is returned. If no character was extracted at all, then null is returned. This method will never return an empty string. |
Remarks
The subfield characters are extracted starting at the given index. Up to nMaxLength characters are extracted. The subfield characters are collected until the first character that does not belong to the requested character set is encountered, or the end of the Content is reached.
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Either the nLength or the nIndex parameters were negative. |
SwiftException | Thrown if either the nFlags parameter requests a
FixedLength subfield and the actually extracted
subfield length was shorter, or if the nFlags parameter does not include
the Optional flag and no subfield could be
extracted. In either case the exception code will be
MalformedFieldContent and |
ToString()
Formats this SWIFT field as a string
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | SWIFT field formatted as a string, useful for diagnostic output. |
Overrides
Remarks
This will basically format the SWIFT field just as it appears inside a SWIFT message. However, linefeeds are still just linefeeds and are not converted to appropriate CRLF sequence. Als, the field will not have leading CRLF, but rather starts immediately with the colon ':'.
If this is an End-Of-Text marker, then a string that contains a single dash '-' is returned. If this field is null, then the String "null" is returned.