This project is read-only.
2
Vote

nameof operator and type alias issues

description

Consider following cases where nameof operator is used

Following compiles but it should not

using SCGL = System.Collections.Generic.List<int>;
nameof (SCGL);

Following does not compiles but perhaps it should

using SCGL = System.Collections.Generic.List<>;
nameof (SCGL);

Following crashes compiler

using SCGL = System.Collections.Generic.List<int>;
nameof (SCGL.Contains);

comments

nmgafter wrote Aug 22, 2014 at 9:46 PM

The first two issues are by design.

For the first issue, SCGL is in scope and so the name is found. It compiles and works by design.

For the second issue, you cannot have a type alias for an open type. It fails to compile by design.

The third issue is a bug to be fixed.

mareksafar wrote Aug 23, 2014 at 7:01 AM

From design notes
Generic types are recognized by name only. Normally there needs to be a type parameter list (or at least dimension specifier) to disambiguate, but type parameter lists or dimension specifiers are not needed, and in fact not allowed, on the rightmost identifier in a nameof.