Simply: don't. You can get the compiler to tell you:
public static string WhoAmI([CallerMemberName] string caller=null)
{
return caller;
}
...
public string FindMyName
{
get
{
string thisPropertyName = WhoAmI();
//...
}
}
This is great for things like OnPropertyChanged
:
protected virtual void OnPropertyChanged([CallerMemberName] string caller = null)
{
var handler = PropertyChanged;
if(handler != null) handler(this, new PropertyChangedEventArgs(caller));
}
...
public int Foo {
get { return foo; }
set { this.foo = value; OnPropertyChanged(); }
}
public string Bar {
get { return bar; }
set { this.bar = value; OnPropertyChanged(); }
}