在VB.NET方法体中不允许code区? [英] Code regions not allowed within method bodies in VB.NET?

查看:257
本文介绍了在VB.NET方法体中不允许code区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:这个功能现已添加到Visual Studio 2015年,但这个问题将持有一段时间,因为不是每个开发人员或每个开发商店获得获得最新和最伟大的IDE尽快它出来。

Note: This "feature" has now been added to Visual Studio 2015 but the question will hold a while since not every developer or every dev shop gets access to the latest and greatest IDE as soon as it comes out.

原题:

通常我不会需要的甚至可以考虑一个荒谬的特征,例如方法体中的code区,但:我重构VB.NET code,其中的方法经常跑500行$ C的$ C以上,引用这样紧密耦合的code蔑视简单的重构等方法提取。

Normally I wouldn't "need" or even consider a ridiculous feature such as code regions within method bodies but: I'm refactoring VB.NET code where methods routinely run five hundred lines of code or more and the references are so tightly coupled that the code defies simple refactoring such as method extraction.

这就是为什么我想我会尝试的方法体中的区域。我只是想组织code在短期内。但IDE不会让我(导致编译错误。)我只是好奇,为什么?好像code区应该不会影响编译器,智能感知等我失去的东西吗? (还是用VS 2005的BTW。)

And that's why I thought I would try regions within a method body. I just wanted to organize the code for the short term. But the IDE doesn't let me (resulted in a compiler error.) I'm just curious as to why? Seems like code regions shouldn't impact the compiler, intellisense etc. Am I missing something? (Still using VS 2005 btw.)

有趣的:这似乎是特定的语言。这是在C#OK(我没有检查,最初),但不是在VB.NET。

Interesting: This seems to be language specific. It's OK in C# (I didn't check that initially) but not in VB.NET.

public module MyModule
    Sub RunSnippet()
        dim a as A = new A (Int32.MaxValue )

        #region 
        Console.WriteLine ("")
        #end region
       ....

这是得到一个编译器错误,但C#的版本就可以了。

that gets a compiler error but the C# version is ok.

推荐答案

由于 2015年十一月:的Visual Studio 2015年现在是支持,只是做你喜欢什么

As of November 2015: In Visual Studio 2015 it is now supported, just do what you like.

样品code:

With frmMain
   #region "A sample region in odd place"
     .show()
     .text = "Sample"
   #end region
End With

注意: 早期版本的的Visual Studio它似乎不是工作在VB.NET,但在C#这是工作

Note: In earlier versions of Visual Studio it seems that it is not working in VB.NET, but in C# it is working.

这篇关于在VB.NET方法体中不允许code区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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