FlatFile icon indicating copy to clipboard operation
FlatFile copied to clipboard

Rethinking of the engine code initialization. Refer to #24

Open forcewake opened this issue 10 years ago • 0 comments

This is the continuation of the conversation from the https://github.com/forcewake/FlatFile/pull/24#issuecomment-102088350

// Init multi record file engine
var engine =
    EngineFactory.GetEngine(
        new[]
        {
            typeof (SettlementHeaderRecord),
            typeof (TransactionRecord),
            typeof (TransactionDetailRecord),
            typeof (SettlementTrailerRecord)
        },
        s =>
        {
            if (String.IsNullOrEmpty(s) || s.Length < 1) return null;
            switch (s[0])
            {
                case 'H':
                    return typeof(SettlementHeaderRecord);
                case 'D':
                    return typeof(TransactionRecord);
                case 'P':
                    return typeof(TransactionDetailRecord);
                case 'V':
                    return typeof(SettlementTrailerRecord);
            }
            return null;
        });
  1. It's rather hard to read
  2. It's rather hard to extend in future
  3. When we will have a lot of engines we will have a lot of copy-paste code

forcewake avatar May 14 '15 17:05 forcewake