In C# Given a hash table like {id:'1', name:'foo'}
How can I dynamically create an instance of a class that has the same members?
public class product {
public int id;
public string name;
}
I know I'm going to run into problems casting but I will deal with those later. Right now I can't even access the members of the class based on the key of the hashtable. Am I going about this the right way?
This is the way I'm currently going about it.
product p = new product();
Type description = typeof(product);
foreach (DictionaryEntry d in productHash)
{
MemberInfo[] info = description.GetMember((string)d.Key);
//how do I access the member of p based on the memberInfo I have?
//p.<?> = d.Value;
}
Thanks