Visual Studio/C# 自动格式化。我可以控制属性后的换行符吗
Visual Studio 一直这样做:
[DataContract]
public class MyContract
{
[DataMember]
public bool MyBool { get; set; }
[DataMember]
public string MyString { get; set; }
}
我希望这样:
[DataContract]
public class MyContract
{
[DataMember] public bool MyBool { get; set; }
[DataMember] public string MyString { get; set; }
}
如果“public class MyContract”与 [DataContract] 位于同一行,那没什么大不了的。
Visual Studio 似乎有很多详细的自动格式化选项,但我找不到任何有关属性后换行符的选项。我在这里错过了什么吗?或者只是不可用。
编辑:至少,我想要一个“不要更改我输入的内容”格式选项,而不是“始终插入”或“始终删除”换行符选项。非常烦人的是,它在我输入后不断取消我的代码格式。
Visual studio keeps doing this:
[DataContract]
public class MyContract
{
[DataMember]
public bool MyBool { get; set; }
[DataMember]
public string MyString { get; set; }
}
I would like this:
[DataContract]
public class MyContract
{
[DataMember] public bool MyBool { get; set; }
[DataMember] public string MyString { get; set; }
}
No big deal if the 'public class MyContract' is on the same line as the [DataContract].
Visual studio seems to have a lot of detailed autoformatting options, but I can't find any regarding newlines after attributes. Am I missing something here? Or is it just not available.
EDIT: At very least, I'd like a "don't change what I entered" formatting option, as opposed to a "always insert" or "always remove" newline option. It's super-annoying that it keeps unformatting my code after I type.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我通常会在自动格式跳转到我不喜欢的地方时按下 Ctrl-Z。
即,在闭幕式上,它格式化了整个类或方法。输入结束赞誉,看看它如何改变你不喜欢的方式,然后按 Ctrl-Z。 (我知道您正在寻找实际的选择,我不知道是否存在)。
What I usually do is hit Ctrl-Z the very moment autoformat jumps in where I don't appreciate it.
I.e., on a closing accolade, which formats a whole class or method. Type the closing accolade, see it changing the way you don't like it and then hit Ctrl-Z. (I know you were looking for an actual option, I don't know if any exists).
不确定它是否适用于属性,但请查看
Tools
->选项
->文本编辑器
->C#
->格式化
->换行
->将块保留在单行上
或将语句和成员声明保留在同一行上
。Not sure if it works for attributes, but look under
Tools
->Options
->Text Editor
->C#
->Formatting
->Wrapping
->Leave block on single line
orLeave statements and member declarations on the same line
.ReSharper 可以做到这一点。它具有以下选项:
这要花费几美元,但如果您'像我一样痴迷,每一分钱都是值得的。 ;)
我还将
Ctrl+K、Ctrl+D
重新映射到 ReSharper 的静默格式代码,以体验格式化的乐趣。ReSharper can do that. It has options for:
It costs a few bucks but if you're as obsessive as I am it's worth every penny. ;)
I also remap
Ctrl+K, Ctrl+D
to ReSharper's silent format code to experience formatting bliss.对我来说最有效的是禁用自动格式;并粘贴。无论如何,我在这些时候几乎不需要自动格式化。这允许您输入属性并移动它们,而不会受到烦人的干扰。
What worked best for me was to disable auto format on ; and paste. I hardly ever want auto format at these times anyways. This allows you to type out attributes and move them around without pesky interference.
它是 ReSharper。 Extensions/ReSharper/Options/Code Editiong/C#/Formatting Style/ 换行和换行: 换行
和换行:
It is ReSharper. Extensions/ReSharper/Options/Code Editiong/C#/Formatting Style/ Line Breakes and Wrapping:
Line Breaks and Wrapping:
是的,
Ctrl+E, D
是你的朋友。您可以在文本编辑器选项
中优化格式Yeah,
Ctrl+E, D
is your friend. You can optimize the formatting inText editor options