我有课
public class Rule
{
public int IdRule { get;set;}
public string RuleName { get; set; }
}
我有带有值的哈希表列表。有键“idRule”、“ruleName”。例子
List<Hashtable> list = new Hashtable();
list["idRule"] = 1;
list["ruleName"] = "ddd";
我有功能:
private static List<T> Equaler<T>(T newRule)
{
var hashTableList = Sql.Table(NameTable.Rules); //Get table from mssql database
var list = new List<T>();
var fields = typeof (T).GetFields();
foreach (var hashtable in hashTableList)
{
var ormRow = newRule;
foreach (var field in fields)
{
???what write this???
// i need something like
//ormRow.SetValueInField(field, hashtable[field.Name])
}
list.Add(ormRow);
}
return list;
}
调用这个函数:
var rules = Equaler<Rule>(new Rule())
问题:如果我知道变量的字符串名称,如何设置变量的值?