Visual Studio 格式问题
我正在使用 Visual Studio 2008。在我的编辑器中,每当我编写自动属性时,每当我编写“set”并放置分号(;)时,它的“get”和“set”都会换行到一行。像这样:
public string MyProperty
{
get; set;
}
我希望它像这样格式化
public string MyProperty
{
get;
set;
}
目前我在写入后手动将其格式化为这样。如何将其设置为默认格式?
编辑:
选项>文本编辑器> C#>格式化>包装> 在单行上留下块对我来说已经未被选中。
我取消选中“选项”>“选项”中可用的所有三个选项。文本编辑器> C#>格式化>一般,但是没用。还要别的吗?
I am using Visual Studio 2008. In my editor whenever I write an automatic property it's "get" and "set" wraps to a single line whenever I wrote "set" and put semicolon(;). like this:
public string MyProperty
{
get; set;
}
I want it to be formatted like this
public string MyProperty
{
get;
set;
}
Currently I am manually formatting it to this after writing it. How can I set it as a default format?
Edit:
Options > Text Editor > C# > Formatting > Wrapping > Leave block on single line is already unchecked for me.
I unchecked all three option available in Options > Text Editor > C# > Formatting > General, but it doesn't work. Anything else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果将其全部放在一行上,则默认格式设置选项将保留它:
这由以下方式控制:
选项> >文本编辑器> C#>格式化>包装> 将块保留在单行
如果您确实想按照自己的方式格式化它,您可以禁用:
选项>文本编辑器> C#>格式化>一般> 自动格式化已完成的块},
但您可能也想禁用粘贴时自动格式化。
If you put it all on one line, the default formatting options will leave it alone:
This is controlled by:
Options > Text Editor > C# > Formatting > Wrapping > Leave block on single line
If you really want to format it your way, you could disable:
Options > Text Editor > C# > Formatting > General > Automatically format completed block on }
But you'd probably want to disable Automatically format on paste too.
如果您使用 ReSharper,代码编辑 -> C#->格式样式 ->换行和换行有一个选项“将抽象/自动属性/索引器/事件放在单行上”来控制您描述的行为。
If you're using ReSharper, Code Editing -> C# -> Formatting Style -> Line Breaks and Wrapping has an option "Place abstract/auto property/indexer/event on single line" that controls the behavior you describe.
工具->选项->文本编辑器有很多针对各种语言的选项,涉及 Visual Studio 应(或不应)自动设置代码格式的选项。
Tools -> Options -> Text editor has a lot of options for various languages as to how Visual Studio should (or should not) auto-format your code.
查看工具 -> 下选项->文本编辑器 -> C#->格式化。
您可能会在那里找到一个设置,可以按照您想要的方式格式化它。
编辑
这是一种解决方法,但它可以解决问题。
为 automagic 属性制作一个代码片段。这是有关如何执行此操作的更多信息的链接。它需要一些修改,但你可以处理它。 ;)
http://msmvps.com/blogs/kevinmcneish/archive/2007/04/30/property-code-snippet-for-visual-studio-2005.aspx
您是否安装了 coderush 或任何其他代码生成插件?
Look under Tools -> Options -> Text Editor -> C# -> Formatting.
You might find a setting there that will format it how you want.
EDIT
This is a workaround, but it would do the trick.
Make a code snippet for automagic properties. Here is link with more info on how to do that. It will need a little modification, but you can handle it. ;)
http://msmvps.com/blogs/kevinmcneish/archive/2007/04/30/property-code-snippet-for-visual-studio-2005.aspx
Do you have coderush or any other code generating addons installed?
注意 - 我相信这是 https://github.com/dotnet/roslyn/issues/2837 并在 VS2015 Update 1 中修复。
Note - I believe this was https://github.com/dotnet/roslyn/issues/2837 and fixed in VS2015 Update 1.