VB.NET 严格关闭内联选项
有没有办法仅针对一行代码关闭选项严格?
我正在做一些维护工作,我需要在一个地方“作弊”,我不想降低整个文件的标准。
Is there a way to turn option strict off for just a single line of code?
I'm doing some maintenance work and I need to "cheat" in just one place and I don't want to lower the standard for the entire file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
遗憾的是,一个文件中的一行代码是不可能的。 请参阅 MSDN 文档。
另一方面,您可以将单行代码设置为一个单独的函数,将其放入具有部分类属性的新文件中,然后将 Option Strict Off 放在该文件上。 不管怎样,IL 编译器可能会内联你的函数,所以它在速度上是等效的,但从实际的角度来看会很难看。
Sadly, it is not possible for a single line of code in a file. See the MSDN docs.
On the other hand, you could probably make your single line of code a separate function, put that in a new file with partial class attributes, and put Option Strict Off on that one file. The IL compiler will probably inline your function anyway, so it will be equivalent speedwise, but will be ugly from a practical point of view.
由于它必须出现在模块的声明部分,因此
option strict
不能在代码中间使用。 但它可以在每个模块的基础上完成,这可能会有所帮助。《Visual Basic 2005 in a nutshell》一书中没有提到还有另一种打开或关闭它的方法。
Since it must appear in the declarations section of the module then
option strict
can't be used in the middle of code. But it can be done on a per-module basis which might help a little.And there is no mention in the "Visual Basic 2005 in a nutshell" book that suggests there's another method of turning it on or off.
其他一些想法:
A couple other ideas: