public bool GetBool() { if (_cacheSet) { return((bool)_dataCache); } string str = _dataAsString; if (!DbfFieldType.IsBool(_fieldType)) { throw new DbfColumnTypeMismatchException(_fieldType, str, typeof(bool)); } switch ((char)_data[0]) { case 'Y': case 'y': _cacheSet = true; _dataCache = true; return(true); case 'N': case 'n': _cacheSet = true; _dataCache = false; return(false); default: throw new DbfColumnTypeMismatchException(_fieldType, str, typeof(bool)); } }
public decimal GetDecimal() { if (_cacheSet) { return((decimal)_dataCache); } string str = _dataAsString; if (!DbfFieldType.IsFloatingPoint(_fieldType)) { throw new DbfColumnTypeMismatchException(_fieldType, str, typeof(decimal)); } decimal result; if (!decimal.TryParse(str, NumberStyles.Number, null, out result)) { throw new DbfColumnTypeMismatchException(_fieldType, str, typeof(decimal)); } _cacheSet = true; _dataCache = result; return(result); }
public int?GetIntOrNull() { if (_cacheSet) { return(_dataCache as int?); } string str = _dataAsString; if (!DbfFieldType.IsNumeric(_fieldType)) { throw new DbfColumnTypeMismatchException(_fieldType, str, typeof(int)); } int result; if (!int.TryParse(str, out result)) { return(null); } _cacheSet = true; _dataCache = result; return(result); }
public DateTime?GetDateOrNull(string format = "yyyyMMdd") { if (_cacheSet) { return(_dataCache as DateTime?); } string str = _dataAsString; if (!DbfFieldType.IsDate(_fieldType)) { throw new DbfColumnTypeMismatchException(_fieldType, str, typeof(DateTime)); } if (string.IsNullOrWhiteSpace(str)) { return(null); } DateTime result; if (!DateTime.TryParseExact(str, format, null, DateTimeStyles.None, out result)) { throw new DbfDateTimeInvalidFormatException(str, format); } _cacheSet = true; _dataCache = result; return(result); }
internal void AddHeader(DbfHeader header) { if (header == null) { return; } if (DbfFieldType.IsFloatingPoint(header.FieldType) && header.NumDecimalPlaces == 0) { header.FieldType = DbfFieldType.Integer; } _headers.Add(header); }
private char GetFieldType(byte[] data) { if (data.Length != 1) { throw new DbfParseException("Field type must consist of only 1 byte"); } if (!DbfFieldType.IsValidType((char)data[0])) { throw new DbfParseException($"Field is not a valid field type: {(char) data[0]} / {(int) data[0]}"); } return((char)data[0]); }
public string GetString() { if (_cacheSet) { return(_dataCache as string); } string str = _dataAsString; if (!DbfFieldType.IsString(_fieldType)) { throw new DbfColumnTypeMismatchException(_fieldType, str, typeof(string)); } _cacheSet = true; _dataCache = str; return(str); }