I am trying to get the name of a method on a generic interface. I would expect this to work as the type part would be a valid typeof:
//This does not compile
nameof(IGenericInterface<>.Method)
//This would compile
typeof(IGenericInterface<>)
I think this should be valid C# 6 or am I missing something or is their a better way to do this. I don't want to use a string for the Method name as if method is renamed code would break without any build time errors.
Just use a sample type in order to compile.
This is expected. According to the documentation, your expression is disallowed, because it refers to an unbound generic type:
You can work around this limitation by supplying a generic parameter:
Note: I think Microsoft should tweak
nameof
feature to allow references to methods of unbound generic types.