I’m trying to implement a Table, divided this up to 3 levels.
class Field ->
class Record (witch holds a collection of fields ) ->
class Table(witch holds a collection of Records)
now my question is not of the correct way to structure this implementation , although any pointers would be welcomed .
iv’e got a problem with implementing a generic field class
public class Field<T>
{
T value;
Type _type;
string _header;
}
i don’t know what type T would be of so i need to define the class with ,
now the problem that i’m facing is that the collection of Field in the Record class would most likely hold different types of T and that kinda defeats the all purpose
public class Record
{
List<Field<object>> fields ;
}
so now i need to cast the T to object because T wont be of a specific type .
any idea’s the work around this accept drooping the all generics idea and defining value as object , would be most appreciated.
plus any pointers about my implementation idea
my table consists of
class Table
{
KeyValuePair<string,Type>[] columns ;
KeyValuePair<string, Type> primary_key;
string entitie_name ;
List<Reocrd> records ;
}
// the Record class could be created only from a table template just like a datarow
public class Record
{
List<Field<object>> fields ;
string primary_key ;// the name of the field witch i use to extract a value
}
10x in advance.
A pattern you can commonly find in the .NET Framework is to define a non-generic base class or interface:
The Record class exposes a collection of non-generic fields:
If code needs to get the value of fields without boxing, it needs to cast the Field instance to the matching Field<T> first.
Example: