Visual Studio 格式问题

发布于 2024-08-28 08:44:11 字数 455 浏览 5 评论 0原文

我正在使用 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 技术交流群。

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

发布评论

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

评论(5

习惯成性 2024-09-04 08:44:11

如果将其全部放在一行上,则默认格式设置选项将保留它:

public string MyProperty { get; set; }

这由以下方式控制:

选项> >文本编辑器> C#>格式化>包装> 将块保留在单行

如果您确实想按照自己的方式格式化它,您可以禁用:

选项>文本编辑器> C#>格式化>一般> 自动格式化已完成的块}

但您可能也想禁用粘贴时自动格式化

If you put it all on one line, the default formatting options will leave it alone:

public string MyProperty { get; set; }

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.

爱的那么颓废 2024-09-04 08:44:11

如果您使用 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.

秋心╮凉 2024-09-04 08:44:11

工具->选项->文本编辑器有很多针对各种语言的选项,涉及 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.

一梦等七年七年为一梦 2024-09-04 08:44:11

查看工具 -> 下选项->文本编辑器 -> 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?

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