i need to get a list to store all fields - values in a class
the class is just a few of public const string
variables as i pasted below.
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";
}
}
this is a method that returns a list of strings that enables me to have a list of strings representing all my tables columns names , though somthing is not working with this code as i get an error
" Non-static field requires a target".
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();
}
}
trying to use it as follows :
foreach (string tblCol in RobCS_212a.Utils.Reflct.GetClassFields.AsList (DBSchema.HTDB_Tables.TblCustomers))
{
Response.Write(string.Concat(tblCol, "<br />"));
}
Field 'tbName' defined on type 'DBSchema.HTDB_Cols+TblTimeCPAReport' is not a field on the target object which is of type 'DBSchema.HTDB_Cols'.