First of all, I am using .NET Framework 3.5 C# 3.0 and Visual Studio 2008.
Having said that... When using MVVM pattern in WPF applications, I am always using view model properties to bind to objects in the view. When calling OnPropertyChanged from the set implementation I always hard-coded the name of the property as a string.
private string _myProperty;
public string MyProperty
{
get
{
return _myProperty;
}
set
{
if (_myProperty == value) return;
_myProperty = value;
OnPropertyChanged("MyProperty");
}
}
So I always think if there is any way to avoid property name to be hard-coded.
I know there are methods such as using nameof as explained here and here but this is only available in C# 6.0 (.NET Framework 4.6 and above).
Also exists CallerMemberName attribute as explained here and here but again it was released and is only available in C# 5.0 (.NET Framework 4.5) and later.
So I am using .NET Framework 3.5 C# 3.0 hence that I cannot use this approaches.
So how can I avoid property name to be hard-coded when passing it as a paramenter to the OnPropertyChanged method? I would like a solution that do not compromise performance.