VB.NET Turning Option Strict Off In-Line

末鹿安然 提交于 2019-11-28 02:34:44

问题


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.


回答1:


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.




回答2:


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.




回答3:


A couple other ideas:

  • You could code with it mostly off and turn it on now and then to make sure the rest of your code complies
  • You could configure it so that Option Strict is ON for release builds but OFF for debug builds.


来源:https://stackoverflow.com/questions/635342/vb-net-turning-option-strict-off-in-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!