/// <summary>
        /// Gets the <see cref="IFileLayout">layout</see> relevant to this object.
        /// </summary>
        /// <param name="encoder">The <see cref="IFileParserEncoder">encoder</see> to use. If null, the default (EBCDIC 2 ASCII) is used.</param>
        /// <returns>A <see cref="IFileLayout">layout</see> matching this object's properties.</returns>
        public IFileLayout GetFileLayout(IFileParserEncoder encoder = null)
        {
            IFileParserEncoder defEncoder = encoder ?? FileParserEncoder.GetDefaultEncoder();
            IFileLayout        result     = new FileLayout(defEncoder)
            {
                Name         = Name,
                OpenAsText   = OpenAsText,
                RecordLength = RecordLength
            };

            if (OpenAsText)
            {
                result.FillCharacter      = FillCharacter;
                result.TextLineTerminator = TextLineTerminator;
            }
            else
            {
                result.FillByte = FillByte;
            }
            if (HeaderFields != null && HeaderFields.Length > 0)
            {
                System.Collections.Generic.List <IFileField> fields = new System.Collections.Generic.List <IFileField>();
                foreach (SerializableField field in HeaderFields.OrderBy(x => x.StartPosition))
                {
                    fields.Add(field.GetField(defEncoder));
                }
                result.HeaderRecord = new FileRecord(fields.ToArray());
            }
            if (FooterFields != null && FooterFields.Length > 0)
            {
                System.Collections.Generic.List <IFileField> fields = new System.Collections.Generic.List <IFileField>();
                foreach (SerializableField field in FooterFields.OrderBy(x => x.StartPosition))
                {
                    fields.Add(field.GetField(defEncoder));
                }
                result.FooterRecord = new FileRecord(fields.ToArray());
            }
            if (MasterFields != null && MasterFields.Length > 0)
            {
                System.Collections.Generic.List <IFileField> fields = new System.Collections.Generic.List <IFileField>();
                foreach (SerializableField field in MasterFields.OrderBy(x => x.StartPosition))
                {
                    fields.Add(field.GetField(defEncoder));
                }
                result.MasterFields = fields.ToArray();
            }
            return(result);
        }
Пример #2
0
 /// <summary>
 /// .ctor. Must be inherited.
 /// </summary>
 public FileRecordBase()
 {
     Encoder = FileParserEncoder.GetDefaultEncoder();
 }
Пример #3
0
 /// <summary>
 /// .ctor. Creates a new instance of FileParser using the default <see cref="FileParserEncoder">FileParserEncoder</see>.
 /// </summary>
 /// <param name="write">
 /// If <see cref="System.Boolean">true</see>, this will use the default ASCII to EBCDIC
 /// <see cref="IFileParserEncoder">IFileParserEncoder</see> instance for writing binary EBCDIC fields.
 /// If <see cref="System.Boolean">false</see>, this will use the default EBCDIC to ASCII
 /// <see cref="IFileParserEncoder">IFileParserEncoder</see> instance for reading binary EBCDIC fields.
 /// Default is <see cref="System.Boolean">false</see>.
 /// </param>
 public FileParser(bool write = false) : this(FileParserEncoder.GetDefaultEncoder(write))
 {
     records = new List <IFileRecord>();
 }
Пример #4
0
 /// <summary>
 /// .ctor. Must be inherited.
 /// </summary>
 /// <param name="write">
 /// If <see cref="System.Boolean">true</see>, this will use the default ASCII to EBCDIC
 /// <see cref="IFileParserEncoder">IFileParserEncoder</see> instance for writing binary EBCDIC fields.
 /// If <see cref="System.Boolean">false</see>, this will use the default EBCDIC to ASCII
 /// <see cref="IFileParserEncoder">IFileParserEncoder</see> instance for reading binary EBCDIC fields.
 /// Default is <see cref="System.Boolean">false</see>.
 /// </param>
 public FileFieldBase(bool write = false)
 {
     Encoder = FileParserEncoder.GetDefaultEncoder(write);
 }