Nameof () operator for a property of a generic class

I often use the C # 6.0 operator nameof(...)

in my tests to determine if, for example, it INotifyPropertyChanged.PropertyChanged

is called on the correct property. Sometimes I have a generic class that implements an interface INotifyPropertyChanged

:

public ViewModel<T>:INotifyPropertyChanged
{
     public string Name { get; set; }

     public T Value { get; set; }
}

      

To get the name of the property Name

, now I use an arbitrary type to get the name: nameof(ViewModel<string>.Name)

. This solution is possible, but can lead to problems if the generic parameter is limited.

Is it possible to get a name without a specific type? I suggested something like nameof(ViewModel<T>.Name)

or nameof(ViewModel<>.Name)

, but that doesn't work.

+3


source to share





All Articles