예제 #1
0
        public static IX9Record Translate(X9Rec item)
        {
            IX9Record ret;
            var       dataLength = 80;

            switch (item.RecType)
            {
            case "01": ret = new R01(); break;

            case "10": ret = new R10(); break;

            case "20": ret = new R20(); break;

            case "25": ret = new R25(); break;

            case "26": ret = new R26(); break;

            case "50": ret = new R50(); break;

            case "52": dataLength = 117; ret = new R52(); break;

            case "61": ret = new R61(); break;

            case "70": ret = new R70(); break;

            case "90": ret = new R90(); break;

            case "99": ret = new R99(); break;

            default: ret = new Unknown(); break;
            }

            var recLen = item.RecData.Length;

            if (!(ret is Unknown) && dataLength != recLen)
            {
                throw new FormatException($"Record defined as {item.RecType} requires a length of {dataLength} but was {recLen}");
            }
            ret.SetData(item.RecData, item.ImageData);
            if (ret.RecordType != item.RecType)
            {
                throw new ArgumentException("I didn't get what I expected");
            }
            return(ret);
        }