有没有办法让 Visual Studio 2008 停止格式化我的 AutoProperties?
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你确定这是VS2008的问题吗? 因为我的自动属性保持不变...
给定...
它保持为...
即使在我应用格式选择命令之后。
注意:我选择了与您相同的 VS 格式选项。 虽然我用的是VS2008 SP1。
Are you sure this is a problem in VS2008? Because my auto properties stay put...
given...
it stays as ...
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.
惊人的! 我设法弄清楚了。 感谢 Anton 我仔细查看了 Resharper 中的可用设置,并找到了一些答案。
我的解决方案涉及 Resharper 和 VS2008 中的设置组合。
在VS2008中,我关闭了自动格式化完成的语句;
然后,我打开 Resharper 中 IntelliSense 完成行为的设置,以在完成后自动插入括号。
这允许我输入:
To get:
然后允许我添加 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:
To get:
Which then allows me to add the get; and set; lines without them formatting...
ReSharper 可能有这样的功能,尽管我不太确定。
ReSharper might have such feature, though I'm not absolutely sure.