Linux 用太多 { 在代码上生成方法存根

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3677055/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 23:10:33  来源:igfitidea点击:

Generate method stub on code with too many {

c#visual-studio-2008

提问by Default

I just noticed that when you try to generate a method stub on code where there are more {than }, the method stub gets generated incorrectly.

我刚刚注意到,当您尝试在{超过 的代码上生成方法存根时},方法存根会被错误地生成。

For instance:

例如:

    static void Main(string[] args) {
        myMethod();
    }

creating a method stub for myMethod()expands correctly into:

创建一个方法存根以myMethod()正确扩展为:

    static void Main(string[] args) {
        myMethod();
    }

    private static void myMethod() {
        throw new NotImplementedException();
    }

However! If I now continue and add:

然而!如果我现在继续并添加:

{
    newMethod();

And try to generate a method stub for newMethod(), I get this:

并尝试为 生成一个方法存根newMethod(),我得到了这个:

        static void Main(string[] args) {
            myMethod();
            {
                newMethod();
        }

        private

private static void newMethod()
{
    throw new NotImplementedException();
} static void myMethod() {
            throw new NotImplementedException();
        }
    }

Can I configure Visual Studio somehow as to do it correctly? Or is this something that would have to be reported to someone?

我可以以某种方式配置 Visual Studio 以正确执行它吗?或者这是必须向某人报告的事情?

采纳答案by Dave Downs

I think this is a case of garbage in, garbage out.

我认为这是垃圾进,垃圾出的情况。

If your code is written in such a way that it's impossible for the auto-generation tools to tell where one code block ends and another begins then I wouldn't expect it to be able to produce meaningful results.

如果您的代码的编写方式使得自动生成工具无法判断一个代码块的结束位置和另一个代码块的开始位置,那么我不希望它能够产生有意义的结果。

回答by kbrimington

If you consider this behavior a bug, I recommend reporting it to Microsoft Connect.

如果您认为此行为是一个错误,我建议您将其报告给Microsoft Connect

Of course, the simple solution is to have well-formatted code prior to using code gen and automated refactor routines. I can't imagine how the text editor could "correctly" handle the potentially-unlimited variety of malformed code.

当然,简单的解决方案是在使用代码生成和自动重构例程之前拥有格式良好的代码。我无法想象文本编辑器如何“正确”处理可能无限多种格式错误的代码。