如何使用 R# 格式化静态变量声明?
private static readonly Dictionary<int, LocalizationLanguage> _languages = new Dictionary<int, LocalizationLanguage>() {
{0,new LocalizationLanguage { CultureInfo = "en-US", Id = 0 }},
{1,new LocalizationLanguage { CultureInfo = "es-AR", Id = 1 }}
};
我有这个声明,它不会自动包装成好的东西,而如果我做完全相同的事情,但使用属性访问器,它的格式完美地为:
private static Dictionary<int, LocalizationLanguage> _languages
{
get
{
return new Dictionary<int, LocalizationLanguage>()
{
{0, new LocalizationLanguage {CultureInfo = "en-US", Id = 0}},
{1, new LocalizationLanguage {CultureInfo = "es-AR", Id = 1}}
};
}
}
这是什么原因以及如何使 vs2010 或 R# 自动 -格式化这种表达式?
private static readonly Dictionary<int, LocalizationLanguage> _languages = new Dictionary<int, LocalizationLanguage>() {
{0,new LocalizationLanguage { CultureInfo = "en-US", Id = 0 }},
{1,new LocalizationLanguage { CultureInfo = "es-AR", Id = 1 }}
};
I have this declaration, and it doesn't autowrap into something nice, whereas if I do the exact same but with a property accessor, it formats perfectly to:
private static Dictionary<int, LocalizationLanguage> _languages
{
get
{
return new Dictionary<int, LocalizationLanguage>()
{
{0, new LocalizationLanguage {CultureInfo = "en-US", Id = 0}},
{1, new LocalizationLanguage {CultureInfo = "es-AR", Id = 1}}
};
}
}
What's the reason for this and how can I make either vs2010 or R# auto-format this kind of expressions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚自己测试过,因为我自己使用 vs2010 和 R#。它会自动将代码重新格式化为:
vs2010 在完成语句(输入
;
)后重新格式化代码。我通过将未格式化的代码粘贴到 Visual Studio 中进行测试,并删除最后的};
。再次输入会自动格式化。我还在关闭语句之前测试了原始代码的不同变体,并且无论如何它的格式都是相同的。我猜你的 vs2010 或 R# 在这种情况下有问题?
I've just tested this myself, as I use vs2010 and R# myself. It automatically reformats the code to:
vs2010 reformats the code upon completion of the statement (entering the
;
). I tested by pasting your unformatted code into visual studio, and erasing the final};
. Typing it again automatically formats it. I also tested having different variations of the original code before closing the statement and it formats it the same no matter what.I would guess there is an issue with your vs2010 or R# in this case?