Last month I received an e-mail from someone that was having problems implementing the library. It didn’t parse it’s format correctly. After he send me the file he was trying to parse I realized supporting different bank formats is too much work.

You needed to implement an interface and pass that around. This interface defines where a message starts and where it ends. Every bank has it’s own format for this. The format is a simple sequence of one ore more strings.

public interface IMt940Format
{
    Separator Header { get; }
    Separator Trailer { get; }
}

Because I wanted to enable quick testing I added the Generic Format class. This class implements the correct interface and allows to specify the correct tokens by passing them in the constructor of the class.

public class GenericFormat : IMt940Format
{    
    public Separator Header { get; private set; }
    public Separator Trailer { get; private set; }

    public GenericFormat(Separator header, Separator trailer)
    {
        Header = header;
        Trailer = trailer;
    }
}

This class can then be used to parse the file more easily for your bank. And can be used as an entry-point for dynamic specification. So now you can save the formats in XML or a database and load them from there. This allows you to add additional bank formats, without recompiling the code.

var header = new Mt940Format.Separator("STARTUMSE");
var trailer = new Mt940Format.Separator("-");
var generic = new Mt940Format.GenericFormat(header, trailer);

var parsed = Mt940Parser.Parse(generic, fileName);

It’s a small thing but this makes life a bit more easy.