How can I refer to the properties of an object of type Employee, for example, dynamically? I'm after something like employee."hasBeenPaid"
? Does it involve reflection?
class Employee
{
String name;
Bool hasBeenPaid;
}
How can I refer to the properties of an object of type Employee, for example, dynamically? I'm after something like employee."hasBeenPaid"
? Does it involve reflection?
class Employee
{
String name;
Bool hasBeenPaid;
}
You could try:
Type type = your_class.GetType();
PropertyInfo propinfo = type.GetProperty("hasBeenPaid");
If you need the value
value = propinfo.GetValue(your_class, null);
You may use the dynamic C# feature; and yes, it will use reflection at runtime to resolve your properties.