Can I convert Class into Dictionary<string, string>?
In Dictionary I want my class properties as keys and value of particular a property as the value.
Suppose my class is
public class Location
{
public string city { get; set; }
public string state { get; set; }
public string country { get; set;
}
Now suppose my data is
city = Delhi
state = Delhi
country = India
Now you can understand my point easily!
I want to make a Dictionary! That dictionary should be like:
Dictionary<string,string> dix = new Dictionary<string,string> ();
dix.add("property_name", "property_value");
I can get the value! But how can I get property names (not value)?
What should I code to create it dynamic? That should work for every class which I want.
You can understand this question as:
How can I get a list of properties from particular class?
Now again I am explaining one of my eagernesses about Dictionary! This question popuped in my mind from answer of my previous question!!
Country
and city is of typestring
, in a dictionary you have to specify the most basic type you are going to store (most likelyobject
) which will make your life harder further along the road.