如何使MonoDevelop从C#6.0中识别nameof语法? [英] How do I make MonoDevelop recognize nameof syntax from C# 6.0?
问题描述
我正在使用MonoDevelop v5.9.6.尽管它似乎支持C#6.0,但该编辑器无法识别nameof
关键字,并且将其标记为红色,因为它试图将其识别为标识符.
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.
在没有以某种方式破坏编译的情况下,我可以使用任何技巧使它在编辑器中工作吗?
Is there any hack I can use to make it work in the editor, without breaking the compilation somehow?
推荐答案
此技巧有效:
// hack to make MonoDevelop recognize nameof syntax from C#6.0
using nameof = System.Func<string>;
编辑器将其识别为返回字符串",并且与参数一起使用时不会出现任何错误,例如nameof(object.Equals)
.
The editor recognizes it as "returning a string" and doesn't give any errors when used with an argument, like, for instance nameof(object.Equals)
.
当我 Ctrl + Shift + Space 显示调用的签名时,VSCode会忽略它,而MonoDevelop会显示以下内容:
When I Ctrl+Shift+Space to show the signature of the call, VSCode ignores it, and MonoDevelop shows this:
VSCode(支持nameof语法)也没有抱怨.词法分析器将nameof
识别为关键字(红色),但是当我将鼠标悬停时将其识别为委托.
无论如何我都不会出错.
VSCode (which supports the nameof syntax) doesn't complain about it either. The lexer recognizes the nameof
as a keyword (in red) but identifies it as a delegate when I hover.
In any case I don't get any errors.
更令人着迷的是,编译器(Mono和VS)只是忽略了using
指令,还接受了nameof
的用法,该用法正常工作.
What is even more intriguing, the compilers (both Mono and VS) simply ignore the using
instruction and also accept usages of nameof
, which works normally.
现在,后续问题将会是...为什么?编译器为什么不抱怨呢?
Now, the followup question would be... why though? Why won't the compilers complain about it?
这篇关于如何使MonoDevelop从C#6.0中识别nameof语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!