I want to increase the maintainability by passing a delegate rather than a const string. What I've done is like this;
var propertyName = SprintMetrics.GetNameOf(metric => metric.Productivity); //Should be : "Productivity"
and:
public static string GetNameOf(Func<SprintMetrics, double> valueFunc)
{
return valueFunc.GetMethodInfo().Name; //Result is : <Excute>b_40....
}
During the debug, I walked throw "valueFunc", and there was no "Productivity" anywhere.
Is there any way to get the property's name "Productivity"? Thanks.
According to Access Denied's answer below, it can be done by both of the following:
var p = nameof(SprintMetrics.Productivity); //"Productivity"
var metrics = new SprintMetrics();
p = nameof(metrics.Productivity); //"Productivity"