Is there any way to stringify a member name in C# for .NET 4.0 like you would in C by using the #define str(s) #s
macro?
public Double MyDouble
{
get { return _MyDouble;}
set
{
_MyDouble = value;
RaisePropertyChanged("MyDouble");
// The below item would refactor correctly if C# had a stringify pre-processor
// RaisePropertyChanged(str(MyDouble));
}
}
private Double _MyDouble;
Re-factorization breaks the raise property changed event if I have Search in Strings
disabled or breaks completely unrelated strings if it is enabled. Sometimes I won't notice until a UI element no longer responds to changes.
No, unfortunately. Currently you would have to use something like PostSharp or NotifyPropertyWeaver to do this reliably.
Note that in C# 5 you'll be able to do this:
And you would use it like so:
And the C# 5 compiler will automatically fill in the the optional parameter.
For your specific case of
OnPropertyChanged
the best you could do is the following (though not ideal obviously)......and...
...along these lines....
I'm not familiar with the C construct, but it sounds awfully like the
nameof
keyword introduced in C# 6 which isIf we wire it in:
...and set a property value,
RaisePropertyChanged
receives a string argument of "MyDouble".