I am trying to use system Reflection
to enable extraction of a class member
(type int
)
var CurrTblID = typeof(currProjData).GetMembers(
BindingFlags.Public |BindingFlags.Static
).Select(t => t.Name)...what expresssion should I put here?
this will expose an enumerator
, with the interface iEnumerable
and assign it to CurrTblID
so i could use foreach
loop , to find which "table ID" Tid
is the current one
- How Can i get to a specific field name and find out its value without the foreach?
the Source for the question is in thecurrProjData
class , shown below.
some background if needed for the answer :
in this code i am using a struct that enables setting Sql server
Database table
with details for later use.
i couldnt find answer for that in sql server so i've made
a struct to hold a custom index
- as a numeric ID
for each table i will use in my application .
public class DBMetaDetails
{
public struct DbTable
{
public DbTable(string tableName, int tableId): this()
{
this.TableName = tableName;
this.TableID = tableId;
}
public string TableName { get; set; }
public int TableID { get; set; }
}
}
TableID
is a custom numeric "id" i am using via that struct,
so this is how i could reference the SQL table
by a custom "index" rather its database name .
public static class currProjData
{
static DBMetaDetails.DbTable CustomersMeta = new DBMetaDetails.DbTable();
static DBMetaDetails.DbTable TimesMeta = new DBMetaDetails.DbTable();
public static void SetTablesMetaDetails()
{
TimesMeta.TableID = HTtIDs.TblTimes;
TimesMeta.TableName = HTDB_Tables.TblTimes;
CustomersMeta.TableID = HTtIDs.TblCustomers;
CustomersMeta.TableName = HTDB_Tables.TblTimeCPAReport;
}
public static readonly int CustomersTid = CustomersMeta.TableID;
public static readonly string CustomersTblName = CustomersMeta.TableName;
public static readonly int TimesTid = TimesMeta.TableID;
public static readonly string TimesTblName = TimesMeta.TableName;
}