public class Foo
{
public string Bar {get; set;}
}
How do I get the value of Bar, a string property, via reflection? The following code will thr
To get the property names of the object by just passing the object you can use this function may this works.
just make object object a class and pass into it.
public void getObjectNamesAndValue(object obj)
{
Type type = obj.GetType();
BindingFlags flags = BindingFlags.Public | BindingFlags.Instance;
PropertyInfo[] prop = type.GetProperties(flags);
foreach (var pro in prop)
{
System.Windows.Forms.MessageBox.Show("Name :" + pro.Name + " Value : "+ pro.GetValue(obj, null).ToString());
}
}
But this will only work when the object properties are "Public"