【问题标题】:Resharper named arguments for methods, but position for expression treesResharper 为方法命名参数,但为表达式树命名
【发布时间】:2019-07-02 10:46:04
【问题描述】:

我们想为方法使用命名参数,所以我将设置更改为:

当我应用这种风格时,它确实为我的所有方法放置了命名参数。但它也更新了我拥有的任何 linq 表达式,这会导致此错误:

表达式树可能不包含命名参数规范

我怎样才能更清晰地忽略 linq 表达式?

这是我应用样式之前的一些代码:

public class MessageService : Service<Message>, IMessageService
{
    public MessageService(DbContext context) : base(context) { }

    public IQueryable<Message> List(string status) => List().Where(m => m.Status.Equals(status)).OrderBy(m => m.NiceEndpoint.StartsWith("PSC") ? 0 : 1).ThenBy(m => m.DateCreated);
    public IQueryable<Message> ListByType(string type, string status) => List().Where(m => m.Type.Equals(type, StringComparison.OrdinalIgnoreCase) && m.Status.Equals(status)).OrderBy(m => m.NiceEndpoint.StartsWith("PSC") ? 0 : 1).ThenBy(m => m.DateCreated);
    public IQueryable<Message> ListByEndpoint(string endpoint, string status) => List().Where(m => m.Type.Equals(endpoint, StringComparison.OrdinalIgnoreCase) && m.Status.Equals(status, StringComparison.OrdinalIgnoreCase)).OrderBy(m => m.NiceEndpoint.StartsWith("PSC") ? 0 : 1).ThenBy(m => m.DateCreated);
    public async Task<Message> GetAsync(string id) => await List().SingleOrDefaultAsync(m => m.Id.Equals(id));
}

当我应用上面的代码样式时,我得到了这个:

public class MessageService : Service<Message>, IMessageService
{
    public MessageService(DbContext context) : base(context: context) { }

    public IQueryable<Message> List(string status) => List().Where(m => m.Status.Equals(value: status)).OrderBy(m => m.NiceEndpoint.StartsWith("PSC") ? 0 : 1).ThenBy(m => m.DateCreated);
    public IQueryable<Message> ListByType(string type, string status) => List().Where(m => m.Type.Equals(value: type, comparisonType: StringComparison.OrdinalIgnoreCase) && m.Status.Equals(value: status)).OrderBy(m => m.NiceEndpoint.StartsWith("PSC") ? 0 : 1).ThenBy(m => m.DateCreated);
    public IQueryable<Message> ListByEndpoint(string endpoint, string status) => List().Where(m => m.Type.Equals(value: endpoint, comparisonType: StringComparison.OrdinalIgnoreCase) && m.Status.Equals(value: status, comparisonType: StringComparison.OrdinalIgnoreCase)).OrderBy(m => m.NiceEndpoint.StartsWith("PSC") ? 0 : 1).ThenBy(m => m.DateCreated);
    public async Task<Message> GetAsync(string id) => await List().SingleOrDefaultAsync(m => m.Id.Equals(value: id));
}

如您所见,它在 linq 表达式中添加了命名参数,但无法编译......

【问题讨论】:

  • 此错误应在 ReSharper 2019.1 中修复。你用的是哪个版本?
  • 我会试一试,让你知道
  • 我可以确认最新版本确实有效
  • 谢谢,我会创建一个答案,以防其他人有同样的问题

标签: c# resharper


【解决方案1】:

此错误应该在 ReSharper 2019.1 中修复,请更新

【讨论】:

    猜你喜欢
    • 2012-04-25
    • 1970-01-01
    • 2012-05-16
    • 1970-01-01
    • 1970-01-01
    • 2021-04-26
    • 1970-01-01
    • 2016-04-06
    相关资源
    最近更新 更多