public IList <DbfColumn> ReadColumns(Stream stream) { var count = Header.HeaderLength - DbfHeader.DbfHeaderSize; var buffer = new byte[count]; stream.Read(buffer, 0, count); var span = new ReadOnlySpan <byte>(buffer); var columns = new List <DbfColumn>(); var start = 0; var startField = 1; var ordinal = 0; while (span[start] != Terminator) { var slice = span.Slice(start, DbfColumn.DbfColumnSize); var column = new DbfColumn(slice, startField, ordinal, CurrentEncoding); columns.Add(column); ordinal++; start = ordinal * DbfColumn.DbfColumnSize; startField += column.Length; } return(columns); }
public IList <DbfColumn> ReadColumns(BinaryReader binaryReader) { var columns = new List <DbfColumn>(); var ordinal = 0; while (binaryReader.PeekChar() != Terminator) { var column = new DbfColumn(binaryReader, ordinal++, CurrentEncoding); columns.Add(column); } var terminator = binaryReader.ReadByte(); if (terminator != Terminator) { throw new DbfFileFormatException(); } return(columns); }
private static IDbfValue CreateDbfValue(DbfColumn dbfColumn, DbfMemo memo, DbfDataReaderOptions options) { IDbfValue value; switch (dbfColumn.ColumnType) { case DbfColumnType.Number: if (dbfColumn.DecimalCount == 0) { value = new DbfValueInt(dbfColumn.Length); } else { value = new DbfValueDecimal(dbfColumn.Length, dbfColumn.DecimalCount); } break; case DbfColumnType.Signedlong: value = new DbfValueLong(dbfColumn.Length, options); break; case DbfColumnType.Float: value = new DbfValueFloat(dbfColumn.Length); break; case DbfColumnType.Currency: value = new DbfValueCurrency(dbfColumn.Length, dbfColumn.DecimalCount, options); break; case DbfColumnType.Date: value = new DbfValueDate(dbfColumn.Length); break; case DbfColumnType.DateTime: value = new DbfValueDateTime(dbfColumn.Length); break; case DbfColumnType.Boolean: value = new DbfValueBoolean(dbfColumn.Length); break; case DbfColumnType.Memo: value = new DbfValueMemo(dbfColumn.Length, memo); break; case DbfColumnType.Double: value = new DbfValueDouble(dbfColumn.Length); break; case DbfColumnType.General: case DbfColumnType.Character: value = new DbfValueString(dbfColumn.Length); break; default: value = new DbfValueNull(dbfColumn.Length); break; } return(value); }
private IDbfValue CreateDbfValue(DbfColumn dbfColumn, DbfMemo memo) { IDbfValue value; switch (dbfColumn.ColumnType) { case DbfColumnType.Number: if (dbfColumn.DecimalCount == 0) { if (dbfColumn.Length < 10) { value = new DbfValueInt(dbfColumn.Start, dbfColumn.Length); } else { value = new DbfValueInt64(dbfColumn.Start, dbfColumn.Length); } } else { value = new DbfValueDecimal(dbfColumn.Start, dbfColumn.Length, dbfColumn.DecimalCount); } break; case DbfColumnType.SignedLong: value = new DbfValueLong(dbfColumn.Start, dbfColumn.Length); break; case DbfColumnType.Float: value = new DbfValueFloat(dbfColumn.Start, dbfColumn.Length, dbfColumn.DecimalCount); break; case DbfColumnType.Currency: value = new DbfValueCurrency(dbfColumn.Start, dbfColumn.Length, dbfColumn.DecimalCount); break; case DbfColumnType.Date: value = new DbfValueDate(dbfColumn.Start, dbfColumn.Length); break; case DbfColumnType.DateTime: value = new DbfValueDateTime(dbfColumn.Start, dbfColumn.Length); break; case DbfColumnType.Boolean: value = new DbfValueBoolean(dbfColumn.Start, dbfColumn.Length); break; case DbfColumnType.Memo: value = new DbfValueMemo(dbfColumn.Start, dbfColumn.Length, memo, _encoding); break; case DbfColumnType.Double: value = new DbfValueDouble(dbfColumn.Start, dbfColumn.Length, dbfColumn.DecimalCount); break; case DbfColumnType.General: case DbfColumnType.Character: value = new DbfValueString(dbfColumn.Start, dbfColumn.Length, _encoding); break; default: value = new DbfValueNull(dbfColumn.Start, dbfColumn.Length); break; } return(value); }