我试图实现一个表,将其分成3个级别。C中的泛型问题#
class Field ->
class Record (witch holds a collection of fields) ->
class Table(witch holds a collection of Records)
现在我的问题是不正确的方式来构造这个实现,虽然任何指针都会受到欢迎。
iv'e有一个问题与实现一个通用类领域
public class Field<T>
{
T value;
Type _type;
string _header;
}
我不知道是什么类型T会的,所以我需要定义与我”, 现在的问题类米面对的是场记录中的类集合将最有可能持有的不同类型的牛逼和这有点儿违背了所有目的
public class Record
{
List<Field<object>> fields ;
}
所以现在我需要将T转换为对象,因为T不会是特定的类型。
任何想法的工作围绕此接受下垂所有的泛型概念和定义值为对象,将不胜感激。
加上我的想法实现任何指针
我的表提前由
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
}
10倍。
你似乎是重新发明轮子呢? –
单靠仿制药无法做到这一点。您将需要:a)为您的班级的用户承担责任,要求提供特定类型的数据,或者b)使用代码生成功能从您的数据库创建非泛型班级,或c)使用反思。 – Jon
这可能是一个天真的问题,但你为什么要创建似乎模仿ado.net数据表和对象的数据行(可能是datacolumn?)? – adrianos