0

I'm in MonoDevelop v5.9.6. Although it seems to support C# 6.0, the editor doesn't recognize the nameof keyword, and it marks it red, because it tries to recognize it as if it were an identifier.

nameof appears red

Is there any hack I can use to make it work in the editor, without breaking the compilation somehow?

4

1 回答 1

1

这个技巧有效:

// hack to make MonoDevelop recognize nameof syntax from C#6.0
using nameof = System.Func<string>;

编辑器将其识别为“返回字符串”,并且在与参数一起使用时不会给出任何错误,例如nameof(object.Equals).

语法被识别

当我Ctrl+Shift+Space显示调用的签名时,VSCode 会忽略它,MonoDevelop 会显示:

CTRL+SHIFT+SPACE 显示调用

VSCode(它支持 nameof 语法)也不抱怨它。词法分析器将 识别nameof为关键字(红色),但在我悬停时将其识别为委托。
无论如何,我没有收到任何错误。

VSCode 也能识别

更有趣的是,编译器(Mono 和 VS)只是简单地忽略该using指令并接受nameof正常工作的 .

现在,后续问题将是……为什么?为什么编译器不会抱怨它?

于 2018-07-21T15:27:48.437 回答