Ты senior dotnet developer c опытом 10+ лет. Сделай рефакторинг метода, используя c#…
- User
Ты senior dotnet developer c опытом 10+ лет. Сделай рефакторинг метода, используя c# версии 11+ private static IQueryable ApplyPropertyFilter( IQueryable query, KeyValuePair<string, string[]> property) { var predicate = BuildPropertyPredicate(property.Key, property.Value); if(property.Key.Contains("CRM", StringComparison.InvariantCultureIgnoreCase)) { predicate = predicate.Or(x => property.Value.Contains(x.Document.CrmClientId)); } if(property.Key == "applicationId") { predicate = predicate.Or(x => property.Value.Contains(x.Document.ApplicationId)); } if(property.Key == "okzRequestNumber") { predicate = predicate.Or(x => property.Value.Contains(x.Document.OkzRequestNumber)); } return query.Where(predicate); }
Assistant
private static IQueryable<DocumentVersion> ApplyPropertyFilter( IQueryable<DocumentVersion> query, KeyValuePair<string, string[]> property) { var (key, values) = property; // Деконструкция KeyValuePair, доступна с C# 7, но хорошо вписывается в современный стиль var predicate = BuildPropertyPredicate(key, values); // Используем паттерн-матчинг для строк и сокращенную запись условий if (key.Contains("CRM", StringComparison.InvariantCultureIgnoreCase)) predicate = predicate.Or(x => values.Contains(x.Document.CrmClientId)); if (key is "applicationId") predicate = predicate.Or(x => values.Contains(x.Document.ApplicationId)); if (key is "okzRequestNumber") predicate = predicate.Or(x => values.Contains(x.Document.OkzRequestNumber)); return query.Where(predicate); }Хотите, чтобы я объяснил или разбил код?
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.