internal ChoFixedLengthRecordConfiguration(Type recordType) : base(recordType)
        {
            FixedLengthRecordFieldConfigurations = new List <ChoFixedLengthRecordFieldConfiguration>();

            if (recordType != null)
            {
                Init(recordType);
            }

            FileHeaderConfiguration = new ChoFixedLengthFileHeaderConfiguration(recordType, Culture);
        }
Exemple #2
0
        internal ChoFixedLengthRecordConfiguration(Type recordType) : base(recordType)
        {
            FixedLengthRecordFieldConfigurations = new List <ChoFixedLengthRecordFieldConfiguration>();

            if (recordType != null)
            {
                Init(recordType);
            }

            FileHeaderConfiguration = new ChoFixedLengthFileHeaderConfiguration(recordType, Culture);
            RecordTypeConfiguration = new ChoFixedLengthRecordTypeConfiguration();
            RecordTypeConfiguration.DefaultRecordType = recordType;

            RecordSelector = new Func <object, Type>((value) =>
            {
                Tuple <long, string> kvp = value as Tuple <long, string>;
                string line = kvp.Item2;
                if (line.IsNullOrEmpty())
                {
                    return(RecordTypeConfiguration.DefaultRecordType);
                }

                if (RecordTypeCodeExtractor != null)
                {
                    string rt = RecordTypeCodeExtractor(line);
                    if (RecordTypeConfiguration.Contains(rt))
                    {
                        return(RecordTypeConfiguration[rt]);
                    }
                }
                else
                {
                    if (RecordTypeConfiguration.StartIndex >= 0 && RecordTypeConfiguration.Size == 0)
                    {
                        return(RecordTypeConfiguration.DefaultRecordType);
                    }
                    if (RecordTypeConfiguration.StartIndex + RecordTypeConfiguration.Size > line.Length)
                    {
                        return(RecordTypeConfiguration.DefaultRecordType);
                    }

                    string rtc = line.Substring(RecordTypeConfiguration.StartIndex, RecordTypeConfiguration.Size);
                    if (RecordTypeConfiguration.Contains(rtc))
                    {
                        return(RecordTypeConfiguration[rtc]);
                    }
                }

                return(RecordTypeConfiguration.DefaultRecordType);
            });
        }