using System; namespace GisSharpBlog.NetTopologySuite.IO { /// /// Class for holding the information assicated with a dbase field. /// public class DbaseFieldDescriptor { // Field Name // Field Type (C N L D or M) // Field Data Address offset from the start of the record. // Length of the data in bytes // Field decimal count in Binary, indicating where the decimal is /// /// Field Name. /// public string Name { get; set; } /// /// Field Type (C N L D or M). /// public char DbaseType { get; set; } /// /// Field Data Address offset from the start of the record. /// public int DataAddress { get; set; } /// /// Length of the data in bytes. /// public int Length { get; set; } /// /// Field decimal count in Binary, indicating where the decimal is. /// public int DecimalCount { get; set; } /// /// Returns the equivalent CLR type for this field. /// public Type Type { get { Type type; switch (DbaseType) { case 'L': // logical data type, one character (T,t,F,f,Y,y,N,n) type = typeof(bool); break; case 'C': // char or string type = typeof(string); break; case 'D': // date type = typeof(DateTime); break; case 'N': // numeric type = typeof(double); break; case 'F': // double type = typeof(float); break; case 'B': // BLOB - not a dbase but this will hold the WKB for a geometry object. type = typeof(byte[]); break; default: throw new NotSupportedException("Do not know how to parse Field type " + DbaseType); } return type; } } /// /// /// /// /// public static char GetDbaseType(Type type) { DbaseFieldDescriptor dbaseColumn = new DbaseFieldDescriptor(); if (type == typeof(Char)) { return 'C'; } if (type == typeof(string)) { return 'C'; } else if (type == typeof(Double)) { return 'N'; } else if (type == typeof(Single)) { return 'N'; } else if (type == typeof(Int16)) { return 'N'; } else if (type == typeof(Int32)) { return 'N'; } else if (type == typeof(Int64)) { return 'N'; } else if (type == typeof(UInt16)) { return 'N'; } else if (type == typeof(UInt32)) { return 'N'; } else if (type == typeof(UInt64)) { return 'N'; } else if (type == typeof(Decimal)) { return 'N'; } else if (type == typeof(Boolean)) { return 'L'; } else if (type == typeof(DateTime)) { return 'D'; } throw new NotSupportedException(String.Format("{0} does not have a corresponding dbase type.", type.Name)); } /// /// /// /// public static DbaseFieldDescriptor ShapeField() { DbaseFieldDescriptor shpfield = new DbaseFieldDescriptor(); shpfield.Name = "Geometry"; shpfield.DbaseType = 'B'; return shpfield; } /// /// /// /// public static DbaseFieldDescriptor IdField() { DbaseFieldDescriptor shpfield = new DbaseFieldDescriptor(); shpfield.Name = "Row"; shpfield.DbaseType = 'I'; return shpfield; } } }