我需要一个列表来存储所有字段 - 一个类中的值
该类只是const string
我在下面粘贴的几个公共变量。
public class HTDB_Cols
{
public class TblCustomers
{
public const string CustID = "custID",
Name = "name",
CustType = "custType",
AddDate = "addDate",
Address = "address",
City = "city",
Phone = "phone",
Cell = "cell";
}
}
这是一个返回字符串列表的方法,它使我能够拥有代表我所有表列名称的字符串列表,尽管由于出现错误,因此某些东西无法使用此代码
“非静态字段需要一个目标”。
public class GetClassFields
{
public static List<string> AsList(string TableName)
{
return typeof(HTDB_Cols).GetNestedTypes()
.First(t => String.Compare(t.Name, TableName, true) == 0)
.GetFields()
.Select(f => f.GetValue(null) as string)
.ToList();
}
}
尝试按如下方式使用它:
foreach (string tblCol in RobCS_212a.Utils.Reflct.GetClassFields.AsList (DBSchema.HTDB_Tables.TblCustomers))
{
Response.Write(string.Concat(tblCol, "<br />"));
}
在“DBSchema.HTDB_Cols+TblTimeCPAReport”类型上定义的字段“tbName”不是“DBSchema.HTDB_Cols”类型的目标对象上的字段。