C#:是恢复需要编译警告? [英] C#: Is pragma warning restore needed?

查看:120
本文介绍了C#:是恢复需要编译警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到这样的:

#pragma warning disable warning-list
#pragma warning restore warning-list

在例子中,无论禁用恢复被使用。是否有必要恢复如果我想为一个整体文件已禁用?

In the examples, both disable and restore are used. Is it necessary to restore if I want it disabled for a whole file?

就像,如果我不恢复多远它携带?难道一切之后编译禁用的警告?或者只是该文件的休息吗?抑或是忽略?

Like, if I do not restore, how far does it carry? Are the warnings disabled for everything compiled after that? Or just for the rest of that file? Or is it ignored?

推荐答案

如果你不恢复禁用是对文件的剩余部分活跃。

If you do not restore the disabling is active for the remainder of the file.

有趣的是这种行为的不可以中的language规范
(参见9.5.8节),但是在条件编译符号的9.5.1节并表明这一点,直到文件末尾行为

Interestingly this behaviour is not defined in the language specification. (see section 9.5.8) However the 9.5.1 section on Conditional compilation symbols does indicate this "until end of file behaviour"

的符号保持限定到该相同符号
#undef指令被处理时,或直到到达
源文件的结束。

The symbol remains defined until a #undef directive for that same symbol is processed, or until the end of the source file is reached.

由于预处理器实际上是编译的词法分析阶段的一部分,它是可能的这种行为是对微软和其他所有实现可预见的未来有效的合同(尤其是因为备用将根据源文件编译顺序是非常复杂和不确定性)

Given the 'pre-processor' is actually part of the lexical analysis phase of compilation it is likely that this behaviour is an effective contract for Microsoft's and all other implementations for the foreseeable future (especially since the alternate would be hugely complex and non deterministic based on source file compilation order)

这篇关于C#:是恢复需要编译警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆