i have a dictionary
var dictionary = new Dictionary<string,string>{{"name","Smith"},{"age","20"}};
and i want to map it’s values to a class
class Person{
public string Name {get;set;}
public string Age {get;set;}
}
i tried to do it in this way
public T Map<T>(Dictionary<string, object> row)
{
var p= new Person();
if (row.ContainsKey("name")) Person.Name= row["name"];
if (row.ContainsKey("age")) Person.Age= row["age"];
return (T) p;
}
and the problem is that i fail at return type, i dont know how to cast T to class Person.
any ideas ?
Thanks.
Either:
Or:
Or: