Can you use reflection to find the name of the currently executing method?
As of .NET 4.5, you can also use [CallerMemberName].
Example: a property setter (to answer part 2):
protected void SetProperty<T>(T value, [CallerMemberName] string property = null)
{
this.propertyValues[property] = value;
OnPropertyChanged(property);
}
public string SomeProperty
{
set { SetProperty(value); }
}
The compiler will supply matching string literals at call sites, so there is basically no performance overhead.
For non-async
methods one can use
System.Reflection.MethodBase.GetCurrentMethod().Name;
https://docs.microsoft.com/en-us/dotnet/api/system.reflection.methodbase.getcurrentmethod
Please remember that for async
methods it will return "MoveNext".