I have class
public class Rule
{
public int IdRule { get;set;}
public string RuleName { get; set; }
}
I have List of Hashtable with values. Have key "idRule", "ruleName". Example
List<Hashtable> list = new Hashtable();
list["idRule"] = 1;
list["ruleName"] = "ddd";
I have function:
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;
}
Call this function:
var rules = Equaler<Rule>(new Rule())
Question: How set value for variable if I know its string name?