Class SwiftField
Collects all the information about a single SWIFT field.
public class SwiftField
- Inheritance
-
SwiftField
- Derived
- Inherited Members
Constructors
SwiftField()
Constructs an uninitialized (null) instance of a SwiftField.
public SwiftField()
SwiftField(SwiftFieldType)
Constructs an empty SWIFT field of the given type.
public SwiftField(SwiftFieldType nFieldType)
Parameters
nFieldType
SwiftFieldTypeField type.
SwiftField(string, SwiftBalance)
public SwiftField(string sTag, SwiftBalance aBalance)
Parameters
sTag
stringaBalance
SwiftBalance
SwiftField(string, string)
Constructs a non-generic SWIFT field with the given Tag and Content.
public SwiftField(string sTag, string sContent)
Parameters
sTag
stringField tag. This must not be null and must conform to the SWIFT field tag requirements.
sContent
stringField content. This must not be null.
Exceptions
- ArgumentNullException
One of the arguments was null.
- 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.
public SwiftField(string sTag, string sQualifier, string sContent)
Parameters
sTag
stringField tag. This must not be null and must conform to the SWIFT field tag requirements.
sQualifier
stringMust be a four character Qualifier. Must not be null.
sContent
stringField content. This must not be null.
Exceptions
- ArgumentNullException
One of the arguments was null.
- 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.
public string Content { get; set; }
Property Value
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.
public int ContentLength { get; }
Property Value
DataSourceScheme
The Data Source Scheme (DSS) also known as the Issuer Code of a generic SWIFT field.
public string DataSourceScheme { get; set; }
Property Value
- 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
- ArgumentOutOfRangeException
When an invalid DSS is set, then an ArgumentOutOfRangeException is thrown.
FieldType
The type of this SWIFT field.
public SwiftFieldType FieldType { get; set; }
Property Value
Line
Optional line number where this SWIFT field starts in the surrounding SWIFT message or stream.
public int Line { get; set; }
Property Value
- int
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
- ArgumentOutOfRangeException
An attempt was made to set a negative value.
Qualifier
The Qualifier of a generic SWIFT field.
public string Qualifier { get; set; }
Property Value
- 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
- ArgumentOutOfRangeException
When an invalid Qualifier is set, then an ArgumentOutOfRangeException is thrown.
Tag
The Tag of this SWIFT field.
public string Tag { get; set; }
Property Value
- string
A SWIFT field consists of two digits followed by an optional upper case option letter.
Exceptions
- ArgumentOutOfRangeException
When an invalid SWIFT field tag is set, then an ArgumentOutOfRangeException is thrown.
Methods
ExtractCode(int, SwiftCharsets, bool)
public string ExtractCode(int nLength, SwiftCharsets nCharset, bool fOptional)
Parameters
nLength
intnCharset
SwiftCharsetsfOptional
bool
Returns
Exceptions
ExtractRestart()
public void ExtractRestart()
ExtractSubfield(int, SwiftCharsets, SwiftSubfieldFlags)
Extracts the next generic subfield from the Content of this field.
public string ExtractSubfield(int nLength, SwiftCharsets nCharset, SwiftSubfieldFlags nFlags = SwiftSubfieldFlags.None)
Parameters
nLength
intThe
nCharset
SwiftCharsetsnFlags
SwiftSubfieldFlagsIndicates whether the subfield is Optional, and/or has a FixedLength. Other SwiftSubfieldFlags are not allowed.
Returns
- 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
null
is returned.
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
- 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.
public SwiftBalance ParseBalance()
Returns
- 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
- SwiftException
Thrown if the field content is not according to the expected balance structure. The exception code will be MalformedFieldContent and
this
field reference will be included in the SwiftException instance.
Subfield(int)
Extracts a subfield from the Content of this SwiftField.
public string Subfield(int nIndex)
Parameters
nIndex
intThe index of the subfield to be extracted.
Returns
- string
Returns the requested subfield, or an empty string, if the subfield does not exist. If the Content is
null
, thennull
is returned.
Remarks
This method assumes that the subfields are all delimited by slash characters.
Exceptions
- ArgumentOutOfRangeException
The parameter nIndex was negative.
Subfield(ref int, int, SwiftCharsets, SwiftSubfieldFlags)
Extracts a subfield from the Content of this SwiftField.
public string Subfield(ref int nIndex, int nLength, SwiftCharsets nCharset, SwiftSubfieldFlags nFlags)
Parameters
nIndex
intZero-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.
null
will be returned. The parameter is passed by reference and is updated such that it indexes the first character after the extracted subfield upon return.nLength
intThe 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.
nCharset
SwiftCharsetsThe SWIFT character set of the subfield to be extracted. Extraction stops at the first character that does not belong to this character set.
nFlags
SwiftSubfieldFlagsA combination of flags that controls the subfield extraction. See the documentation of the SwiftSubfieldFlags enumeration for possible flags and their impact.
Returns
- 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
- 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
this
field reference will be included in the SwiftException instance.
ToString()
Formats this SWIFT field as a string
public override string ToString()
Returns
- string
SWIFT field formatted as a string, useful for diagnostic output.
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.