Well, you can use the interface, but if the property can change, you can do it.
First solution: if you need a property name
PrintName<T>(T objectToPrint, Expression<Func<T, object>> property)
Using
PrintName(cat, c=> c.Name)
Then, to get the "name" of the property, something like this.
var name = (property.Body as MemberExpression).Member.Name
Second solution: if you need a property value
if you want to get the value of the property, use the parameter Func<T, object> func
Using
PrintName(cat, c => c.Name)
then
var value = func(cat)
source share