Say I have a class
public class Employee
{
public string name = "";
public int age = 20;
}
now I want a function that can dynamically get the value of a specified member of Employee
public class Util<T>
{
public static string GetValue(T obj, string member)
{
// how to write
}
}
so that I can use it like
Employee p1 = new Employee();
string a = Util<Employee>.GetValue(p1, "age"); // a should be "20"
How to do it? like access member use obj["???"] in PHP