private object CastToColumnType(string columnName, string value) { Guard.AgainstNull(columnName, "Column Name"); if (string.Equals(columnName, "rowid", StringComparison.InvariantCultureIgnoreCase)) { return(Convert.ToInt32(value)); } if (string.Equals(columnName, "obj", StringComparison.InvariantCultureIgnoreCase)) { GeometryBuilder georeader = new GeometryBuilder(this.TableName, this.MapinfoSession); Geometry geo = georeader.CreateGeometry(); return(geo); } string columntypestring = this.MapinfoSession.Eval("ColumnInfo({0},{1},{2})".FormatWith(this.TableName, columnName, 3)); int columntypeval = Convert.ToInt32(columntypestring); ColumnTypes columntype = (ColumnTypes)columntypeval; switch (columntype) { case ColumnTypes.CHAR: return(value); case ColumnTypes.DECIMAL: return(Convert.ToDecimal(value)); case ColumnTypes.INTEGER: return(Convert.ToInt32(value)); case ColumnTypes.SMALLINT: return(Convert.ToInt16(value)); case ColumnTypes.DATE: DateTime date2; bool parsed2 = DateTime.TryParseExact(value, "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out date2); if (parsed2) { return(date2); } else { return(null); } case ColumnTypes.LOGICAL: return(value == "T"); case ColumnTypes.GRAPHIC: break; case ColumnTypes.FLOAT: return(Convert.ToDouble(value)); case ColumnTypes.TIME: break; case ColumnTypes.DATETIME: DateTime date; bool parsed = DateTime.TryParseExact(value, "yyyyMMddHHmmssfff", null, System.Globalization.DateTimeStyles.None, out date); if (parsed) { return(date); } else { return(null); } default: return(null); } return(null); }