-
Notifications
You must be signed in to change notification settings - Fork 3
/
DefaultRecordFactory.cs
66 lines (57 loc) · 2.06 KB
/
DefaultRecordFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
namespace X937
{
public class DefaultRecordFactory : IRecordFactory
{
#region Properties
/// <summary>
/// Gets or sets the types used when instantiating new records.
/// </summary>
/// <value>
/// The types used when instantiating new records.
/// </value>
public Dictionary<int, Type> Types { get; protected set; }
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="DefaultRecordFactory"/> class.
/// </summary>
public DefaultRecordFactory()
{
Types = new Dictionary<int, Type>
{
{ 1, typeof( Records.FileHeader ) },
{ 10, typeof( Records.CashLetterHeader ) },
{ 20, typeof( Records.BundleHeader ) },
{ 25, typeof( Records.CheckDetail ) },
{ 26, typeof( Records.CheckDetailAddendumA) },
{ 50, typeof( Records.ImageViewDetail ) },
{ 52, typeof( Records.ImageViewData ) },
{ 61, typeof( Records.CreditDetail ) },
{ 70, typeof( Records.BundleControl ) },
{ 90, typeof( Records.CashLetterControl ) },
{ 99, typeof( Records.FileControl ) }
};
}
#endregion
#region Methods
/// <summary>
/// Gets a new Record instance that is appropriate for the given record type.
/// </summary>
/// <param name="recordType">The type of record.</param>
/// <returns></returns>
public virtual Record GetRecordForType( int recordType )
{
if ( Types.ContainsKey( recordType ) )
{
return ( Record ) Activator.CreateInstance( Types[recordType] );
}
else
{
throw new ArgumentOutOfRangeException( nameof( recordType ), $"Unknown record type '{recordType}' found." );
}
}
#endregion
}
}