Visual Studio中的Linq查询格式化

5
在Visual Studio 2010中输入以下内容:
using(var myEntities = new MyEntities())
{
    IQueryable<Employee> employees =
        from    e in myEntities.Employees
        where   e.Name == name &&
                e.Password == hasher.ComputeHash(password)
        select  e;

    ...  Code left out for simplicity ...

当我输入闭合括号时,我遇到了格式问题。具体来说,文本编辑器会重新格式化linq查询中的空格,以至于最终结果变成了:

using(var myEntities = new MyEntities())
{
    IQueryable<Employee> employees =
        from e in myEntities.Employees
        where e.Name == name &&
                e.Password == hasher.ComputeHash(password)
        select e;

    ...  Code left out for simplicity ...
}

有没有可能更改Visual Studio的格式设置,以防止空格在我的linq查询中自动删除?我已经尝试过谷歌搜索,并浏览了Visual Studio的工具->选项窗口,但无法找到任何东西。希望我只是忽略了某些东西...提前致谢!
1个回答

4
在VS中,转到“工具”->“选项”,然后选择“文本编辑器”->“C#”->“格式化”->“常规”。取消此页面上至少前两个复选框的勾选。这将防止VS自动格式化您的代码。但是,无法仅禁用LINQ查询的自动格式化。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接