コード例 #1
0
ファイル: DbfColumn.cs プロジェクト: Zonciu/dbfreader
        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));
            }
        }
コード例 #2
0
ファイル: DbfColumn.cs プロジェクト: Zonciu/dbfreader
        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);
        }
コード例 #3
0
ファイル: DbfColumn.cs プロジェクト: Zonciu/dbfreader
        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);
        }
コード例 #4
0
ファイル: DbfColumn.cs プロジェクト: Zonciu/dbfreader
        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);
        }
コード例 #5
0
ファイル: DbfTable.cs プロジェクト: Zonciu/dbfreader
 internal void AddHeader(DbfHeader header)
 {
     if (header == null)
     {
         return;
     }
     if (DbfFieldType.IsFloatingPoint(header.FieldType) && header.NumDecimalPlaces == 0)
     {
         header.FieldType = DbfFieldType.Integer;
     }
     _headers.Add(header);
 }
コード例 #6
0
ファイル: DbfReaderUtil.cs プロジェクト: Zonciu/dbfreader
        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]);
        }
コード例 #7
0
ファイル: DbfColumn.cs プロジェクト: Zonciu/dbfreader
        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);
        }