This post shows you how to get property value from string using reflection in c#.
For example:
public class Temperature
{
public string Location { get; set; }
public decimal Value { get; set; }
public object this[string propertyName]
{
get { return this.GetType().GetProperty(propertyName).GetValue(this, null); }
set { this.GetType().GetProperty(propertyName).SetValue(this, value, null); }
}
}
To get property value in c# you can write.
Temperature t = new Temperature();
var location = t["Localtion"];
var value = Convert.ToInt32(t["Value"]);
As you can see, we will create an indexer allows you get property value from a string in c#.