Dotnet Core-得到对'string.Replace(string,string?)'的警告,说使用'string.Replace(string,string ?, System.StringComparison)'

问题描述 投票:0回答:1

我在“替换”时收到以下警告

> Severity  Code    Description Project File    Line    Suppression State
> Warning   CA1307  The behavior of 'string.Replace(string, string?)' could
> vary based on the current user's locale settings. Replace this call in
> 'JobsLedger.API.ControllerServices.Common.OrderAndFIlterHelpers.ODataProcessQuery.ProcessQuery(string)'
> with a call to 'string.Replace(string, string?,
> System.StringComparison)'.    JobsLedger.API  C:\Users\simon\OneDrive\Documents\1.0
> - AURELIA\1.0 - JobsLedgerSPA -ASPNET CORE 3.1\JobsLedger.API\ControllerServices\Common\OrderAndFIlterHelpers\ODataProcessQuery.cs    38  Active

我不知道如何重新配置​​以下内容以考虑'System.StringComparison':

                            .Replace("and", "&")
                            .Replace("substringof", string.Empty)
                            .Replace("(", string.Empty)
                            .Replace(")", string.Empty)
                            .Replace("'", string.Empty)
                            .Replace(" ", string.Empty)
                            .Replace("eq", ",")

每行都发出了警告。.>

我正在使用VS2019,这些警告来自Roslyn编译器。我想摆脱警告..我如何重写此代码以考虑替换的'System.StringComparison'部分?

我在“替换”上收到以下警告>严重性代码说明项目文件行抑制状态>警告CA1307'string.Replace(string,string?)'的行为...

c# visual-studio roslyn-code-analysis
1个回答
0
投票
只是...告诉它您想要哪种比较类型;例如,对于无序的情况,请替换:
© www.soinside.com 2019 - 2024. All rights reserved.