Before I delve into my question I guess I should give some background as to what it is I'm doing.
I'm working on a GIS based development project using MapInfo's scripting language MapBasic. The data I'm using is to be stored in a SQLite database which needs to be prepared before I use it through MapInfo. As such, I'm writing a .NET library in C# to deal with creating a database and importing CSV files selected through the MapBasic GUI I've developed.
So...
I have a class called Geo_Schema to hold the schemas for the geometry tables that need to be inserted into the database. Within that class I have an array of Table classes. Each table class has an array of field classes within it.
public class Field
{
public string name;
public string type;
}
public class Table : IEnumerable
{
public string name;
public int numFields;
public Field[] fields = new Field[8];
public IEnumerator GetEnumerator()
{
return fields.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return fields.GetEnumerator();
}
}
public class Geo_Schema : IEnumerable
{
public Table[] table = new Table[3];
public IEnumerator GetEnumerator()
{
return table.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return table.GetEnumerator();
}
}
Not sure whether this is a good way of structuring this data to begin with. I think there must be a better way, so my first question is exactly that. Is there a better way to store this table schema data? Should I be using inheritance here? The answer to this question may actually solve the next bit...
I go on to use the above classes in a method, but I am getting an error when attempting to assign values to the class properties. The error reads 'Object reference not set to an instance of an object'.
private static bool CheckMappable(SQLiteConnection conn, String tabName)
{
SQLiteCommand cmd = new SQLiteCommand();
Geo_Schema geo_schema = new Geo_Schema();
geo_schema.table[0].name = "spatial_ref_sys"; geo_schema.table[1].name = "geometry_columns";
geo_schema.table[0].numFields = 7; geo_schema.table[1].numFields = 7;
geo_schema.table[0].fields[0].name = "srid"; geo_schema.table[1].fields[0].name = "f_table_name";
geo_schema.table[0].fields[0].type = "INTEGER PRIMARY KEY"; geo_schema.table[1].fields[0].type = "TEXT";
geo_schema.table[0].fields[1].name = "sr_name"; geo_schema.table[1].fields[1].name = "f_geometry_column";
geo_schema.table[0].fields[1].type = "TEXT"; geo_schema.table[1].fields[1].type = "TEXT";
geo_schema.table[0].fields[2].name = "auth_name"; geo_schema.table[1].fields[2].name = "geometry_type";
geo_schema.table[0].fields[2].type = "TEXT"; geo_schema.table[1].fields[2].type = "INTEGER";
geo_schema.table[0].fields[3].name = "auth_srid"; geo_schema.table[1].fields[3].name = "geometry_dettype";
geo_schema.table[0].fields[3].type = "INTEGER"; geo_schema.table[1].fields[3].type = "INTEGER";
geo_schema.table[0].fields[4].name = "srtext"; geo_schema.table[1].fields[4].name = "coord_dimension";
geo_schema.table[0].fields[4].type = "TEXT"; geo_schema.table[1].fields[4].type = "INTEGER";
geo_schema.table[0].fields[5].name = "sr_xytol"; geo_schema.table[1].fields[5].name = "srid";
geo_schema.table[0].fields[5].type = "REAL"; geo_schema.table[1].fields[5].type = "INTEGER";
geo_schema.table[0].fields[6].name = "sr_ztol"; geo_schema.table[1].fields[6].name = "geometry_format";
geo_schema.table[0].fields[6].type = "REAL"; geo_schema.table[1].fields[6].type = "TEXT";
I don't understand this error as I have created an instance of geo_schema, which as far as I understand creates a new array of Table classes in it's constructor and the Table constructor then does the same for an array of Fields. Can anyone help me to understand what's going on here? I'm relatively new to .NET and C# so apologies if this seems trivial!
Thanks!
IEnumerable<T>.