有没有办法让 Visual Studio 2008 停止格式化我的 AutoProperties?

发布于 2024-07-14 01:44:04 字数 662 浏览 6 评论 0原文

在 Visual Studio 2008 的选项 > 文本编辑器> C#> 格式化,我勾选了以下设置。

  • 自动格式化已完成的语句 ;

  • 自动格式化已完成的块}

这对于我编写方法或 for/foreach/while/if 语句时非常有帮助。

即,如果我写,

void MyMethod(){}

我希望在输入最后一个 } 时将其重新格式化为以下内容 }

void MyMethod()
{
}

但是,当我写时:

bool MyProperty { get; set; }

我希望它保持这种方式而不是更改为:

bool MyProperty 
{ 
    get; 
    set; 
}

无论如何,我可以让这种情况发生吗?我在做梦吗? 我能想到的唯一方法是关闭这两个设置......但这只会导致烦恼转移到我编写方法和 if 语句等时。

更新: 只是想我会提到我使用 Resharper...所以如果有一种方法可以通过那里完成它,我也会有兴趣知道这一点。

In Visual Studio 2008's Options > Text Editor > C# > Formatting, I have the following settings ticked.

  • Automatically format completed statement on ;

  • Automatically format completed block on }

This is really helpful for when I'm writing a method or a for/foreach/while/if statement.

ie if I write

void MyMethod(){}

I want it to reformat it to the following when I type the last }

void MyMethod()
{
}

However, when I write:

bool MyProperty { get; set; }

I want it to stay that way instead of getting changed to:

bool MyProperty 
{ 
    get; 
    set; 
}

Is there anyway that I can get this to happen or am I dreaming? The only way I can think of is turning those two settings off....but that just results in the annoyance getting shifted to when I write methods and if statements etc.

Update:
Just thought I'd mention that I use Resharper...so if there's a way to accomplish it through there I would be interested in knowing that too.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

满天都是小星星 2024-07-21 01:44:04

你确定这是VS2008的问题吗? 因为我的自动属性保持不变...

给定...

bool MyProperty { get; set; }

它保持为...

bool MyProperty { get; set; }

即使在我应用格式选择命令之后。

注意:我选择了与您相同的 VS 格式选项。 虽然我用的是VS2008 SP1。

Are you sure this is a problem in VS2008? Because my auto properties stay put...

given...

bool MyProperty { get; set; }

it stays as ...

bool MyProperty { get; set; }

Even after I apply the format selection command.

Note: I have the same VS formatting options selected as you. Though I am using VS2008 SP1.

乖乖哒 2024-07-21 01:44:04

惊人的! 我设法弄清楚了。 感谢 Anton 我仔细查看了 Resharper 中的可用设置,并找到了一些答案。

我的解决方案涉及 Resharper 和 VS2008 中的设置组合。

在VS2008中,我关闭了自动格式化完成的语句;

然后,我打开 Resharper 中 IntelliSense 完成行为的设置,以在完成后自动插入括号。

这允许我输入:

bool MyProperty {

To get:

bool MyProperty {}

然后允许我添加 get; 并设置; 没有格式化的行...

Awesome! I managed to figure it out. Thanks to Anton I had a closer look at the settings available in Resharper and I was able to figure something out.

My solution involves a combination of settings in Resharper and VS2008.

In VS2008, I turn off Automatically format completed statement on ;

I then turn on the setting in Resharper for IntelliSense Completion Behavior to Automatically insert parentheses after completion.

This allows me to type:

bool MyProperty {

To get:

bool MyProperty {}

Which then allows me to add the get; and set; lines without them formatting...

柠檬色的秋千 2024-07-21 01:44:04

ReSharper 可能有这样的功能,尽管我不太确定。

ReSharper might have such feature, though I'm not absolutely sure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文