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.