I often use the C# 6.0 nameof(...)
operator in tests to determine, if e.g. the INotifyPropertyChanged.PropertyChanged
is called for the right property. Sometimes I have a generic class implementing the INotifyPropertyChanged
interface:
public ViewModel<T>:INotifyPropertyChanged
{
public string Name { get; set; }
public T Value { get; set; }
}
To get the name of the property Name
by now I use a arbitrary type to get the name: nameof(ViewModel<string>.Name)
. This solution is possible but might result in problems, if the generic type parameter gets constrainted.
Is there a possibility to get the name without a specific generic type? I suggested something like nameof(ViewModel<T>.Name)
or nameof(ViewModel<>.Name)
, but that doesn't work.