3

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.

scher
  • 1,813
  • 2
  • 18
  • 39
  • I closed the question as a duplicate because I think the answer is "no, it is not possible", and the other question explains why/how. This could be useful, of course. – Kobi Apr 19 '17 at 13:53

0 Answers0