重新共享方法的命名参数,但表达式树的位置

时间:2019-07-02 10:46:04

标签: c# resharper

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

enter image description here

当我应用这种样式时,它确实为所有方法都放置了命名参数。但是它也会更新我拥有的所有 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表达式中添加了命名参数,这些参数不会编译。...

1 个答案:

答案 0 :(得分:2)

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