diff --git a/eng/CodeAnalysis.src.globalconfig b/eng/CodeAnalysis.src.globalconfig index de0d6e8137e0b8..b4bf73bbcb23fe 100644 --- a/eng/CodeAnalysis.src.globalconfig +++ b/eng/CodeAnalysis.src.globalconfig @@ -475,7 +475,7 @@ dotnet_diagnostic.CA1860.severity = warning dotnet_diagnostic.CA1861.severity = warning # CA1862: Prefer using 'StringComparer'/'StringComparison' to perform case-insensitive string comparisons -dotnet_diagnostic.CA1862.severity = warning +dotnet_diagnostic.CA1862.severity = info # CA1863: Use 'CompositeFormat' dotnet_diagnostic.CA1863.severity = suggestion diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 06d9e1d4f9757b..00812b136ab3dc 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -367,13 +367,13 @@ https://github.com/dotnet/roslyn 7829f6b85177e96de89bc67f32b61d74ac590f5a - + https://github.com/dotnet/roslyn-analyzers - 45879f0b46557886b8d553d121a81866f67ce08a + 633ade7a83c2b6918c10035247d93fbe1520463d - + https://github.com/dotnet/roslyn-analyzers - 45879f0b46557886b8d553d121a81866f67ce08a + 633ade7a83c2b6918c10035247d93fbe1520463d https://github.com/dotnet/sdk diff --git a/eng/Versions.props b/eng/Versions.props index bc9bfb96e1f388..0786f2ee5bec7a 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -32,8 +32,8 @@ - 3.11.0-beta1.23364.2 - 8.0.0-preview.23364.2 + 3.11.0-beta1.23405.1 + 8.0.0-preview.23405.1 false false diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DBCommandBuilder.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DBCommandBuilder.cs index 5b744965e9eb65..387752c8e424b6 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DBCommandBuilder.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DBCommandBuilder.cs @@ -733,11 +733,11 @@ private void BuildInformation(DataTable schemaTable) string quotePrefix = QuotePrefix; string quoteSuffix = QuoteSuffix; - if (!string.IsNullOrEmpty(quotePrefix) && (-1 != baseTableName.IndexOf(quotePrefix, StringComparison.Ordinal))) + if (!string.IsNullOrEmpty(quotePrefix) && baseTableName.Contains(quotePrefix, StringComparison.Ordinal)) { throw ADP.DynamicSQLNestedQuote(baseTableName, quotePrefix); } - if (!string.IsNullOrEmpty(quoteSuffix) && (-1 != baseTableName.IndexOf(quoteSuffix, StringComparison.Ordinal))) + if (!string.IsNullOrEmpty(quoteSuffix) && baseTableName.Contains(quoteSuffix, StringComparison.Ordinal)) { throw ADP.DynamicSQLNestedQuote(baseTableName, quoteSuffix); } diff --git a/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/AD/ADStoreCtx_Query.cs b/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/AD/ADStoreCtx_Query.cs index ec744f624af6ae..b009b3ed540917 100644 --- a/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/AD/ADStoreCtx_Query.cs +++ b/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/AD/ADStoreCtx_Query.cs @@ -1013,10 +1013,7 @@ private void AddPropertySetToTypePropListMap(Type principalType, StringCollectio { lock (TypeToLdapPropListMap) { - if (!TypeToLdapPropListMap[this.MappingTableIndex].ContainsKey(principalType)) - { - TypeToLdapPropListMap[this.MappingTableIndex].Add(principalType, propertySet); - } + TypeToLdapPropListMap[MappingTableIndex].TryAdd(principalType, propertySet); } } } diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.PackUriScheme.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.PackUriScheme.cs index 9912f15555ad9b..2707afbf4b5391 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.PackUriScheme.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.PackUriScheme.cs @@ -285,7 +285,11 @@ private static string EscapeSpecialCharacters(string path) // This is currently enforced by the order of characters in the s_specialCharacterChars array foreach (char c in s_specialCharacterChars) { +#if NET5_0_OR_GREATER + if (path.Contains(c)) +#else if (path.IndexOf(c) != -1) +#endif { path = path.Replace(c.ToString(), Uri.HexEscape(c)); } diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PartBasedPackageProperties.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PartBasedPackageProperties.cs index 526a2bf676d9b5..a5035967e174e9 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PartBasedPackageProperties.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PartBasedPackageProperties.cs @@ -379,7 +379,9 @@ private void RecordNewBinding(PackageXmlEnum propertyenum, object? value, bool i _package.ThrowIfReadOnly(); // Case of an existing property. +#pragma warning disable CA1864 // Prefer the 'IDictionary.TryAdd(TKey, TValue)' method if (_propertyDictionary.ContainsKey(propertyenum)) +#pragma warning restore CA1864 // Cannot use TryAdd because if the value is null it is not added if { // Parsing should detect redundant entries. if (initializing) diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs index d604e8a766c4be..d142afc3e0b577 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs @@ -501,7 +501,7 @@ bool IEqualityComparer.Equals(string? extensionA, string? extensionB) //with the rules for comparing/normalizing partnames. //Refer to PackUriHelper.ValidatedPartUri.GetNormalizedPartUri method. //Currently normalization just involves upper-casing ASCII and hence the simplification. - return extensionA.ToUpperInvariant() == extensionB.ToUpperInvariant(); + return extensionA.Equals(extensionB, StringComparison.InvariantCultureIgnoreCase); } int IEqualityComparer.GetHashCode(string extension) diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpEndPointManager.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpEndPointManager.cs index e6be7fd6a0689e..5077554178e92b 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpEndPointManager.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpEndPointManager.cs @@ -99,7 +99,7 @@ private static void AddPrefixInternal(string p, HttpListener listener) if (lp.Path!.Contains('%')) throw new HttpListenerException((int)HttpStatusCode.BadRequest, SR.net_invalid_path); - if (lp.Path.IndexOf("//", StringComparison.Ordinal) != -1) + if (lp.Path.Contains("//")) throw new HttpListenerException((int)HttpStatusCode.BadRequest, SR.net_invalid_path); // listens on all the interfaces if host name cannot be parsed by IPAddress. @@ -206,7 +206,7 @@ private static void RemovePrefixInternal(string prefix, HttpListener listener) if (lp.Path!.Contains('%')) return; - if (lp.Path.IndexOf("//", StringComparison.Ordinal) != -1) + if (lp.Path.Contains("//")) return; HttpEndPointListener epl = GetEPListener(lp.Host!, lp.Port, listener, lp.Secure); diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs index d9fa4d943bf2aa..cf84520b8549d8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs @@ -5505,8 +5505,7 @@ public void AddEventParameter(Type type, string name) { templates?.Append(" map=\"").Append(type.Name).Append('"'); mapsTab ??= new Dictionary(); - if (!mapsTab.ContainsKey(type.Name)) - mapsTab.Add(type.Name, type); // Remember that we need to dump the type enumeration + mapsTab.TryAdd(type.Name, type); // Remember that we need to dump the type enumeration } templates?.AppendLine("/>"); diff --git a/src/libraries/System.Private.CoreLib/src/System/String.Searching.cs b/src/libraries/System.Private.CoreLib/src/System/String.Searching.cs index c9ec02441a2284..9c8487c77c8999 100644 --- a/src/libraries/System.Private.CoreLib/src/System/String.Searching.cs +++ b/src/libraries/System.Private.CoreLib/src/System/String.Searching.cs @@ -32,7 +32,9 @@ public bool Contains(char value) public bool Contains(char value, StringComparison comparisonType) { +#pragma warning disable CA2249 // Consider using 'string.Contains' instead of 'string.IndexOf'... this is the implementation of Contains! return IndexOf(value, comparisonType) != -1; +#pragma warning restore CA2249 } // Returns the index of the first occurrence of a specified character in the current instance. diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Resolvers/XmlPreloadedResolver.cs b/src/libraries/System.Private.Xml/src/System/Xml/Resolvers/XmlPreloadedResolver.cs index 98a4e76ca380ec..a746ab4e52b55f 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Resolvers/XmlPreloadedResolver.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Resolvers/XmlPreloadedResolver.cs @@ -352,14 +352,7 @@ private void Add(Uri uri, PreloadedData data) Debug.Assert(uri != null); // override if exists - if (_mappings.ContainsKey(uri)) - { - _mappings[uri] = data; - } - else - { - _mappings.Add(uri, data); - } + _mappings[uri] = data; } private void AddKnownDtd(XmlKnownDtdData[] dtdSet) diff --git a/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/Helpers.cs b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/Helpers.cs index 9de7d560950f40..147259b5cde42b 100644 --- a/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/Helpers.cs +++ b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/Helpers.cs @@ -123,7 +123,11 @@ public static bool NeedsEscapingInTypeName(this char c) public static string UnescapeTypeNameIdentifier(this string identifier) { +#if NET5_0_OR_GREATER + if (identifier.Contains('\\')) +#else if (identifier.IndexOf('\\') != -1) +#endif { StringBuilder sbUnescapedName = new StringBuilder(identifier.Length); for (int i = 0; i < identifier.Length; i++) diff --git a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/Rss20FeedFormatter.cs b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/Rss20FeedFormatter.cs index 6514dcb5f576a5..b71004972ad700 100644 --- a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/Rss20FeedFormatter.cs +++ b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/Rss20FeedFormatter.cs @@ -378,7 +378,7 @@ private void ReadItemFrom(XmlReader reader, SyndicationItem result, Uri feedBase { bool isPermalink = true; string permalinkString = reader.GetAttribute(Rss20Constants.IsPermaLinkTag, Rss20Constants.Rss20Namespace); - if ((permalinkString != null) && (permalinkString.ToUpperInvariant() == "FALSE")) + if (permalinkString != null && permalinkString.Equals("FALSE", StringComparison.InvariantCultureIgnoreCase)) { isPermalink = false; } diff --git a/src/libraries/System.Speech/src/Internal/SrgsParser/XmlParser.cs b/src/libraries/System.Speech/src/Internal/SrgsParser/XmlParser.cs index 79c87dfa6d34b0..7acbf9c03bdf15 100644 --- a/src/libraries/System.Speech/src/Internal/SrgsParser/XmlParser.cs +++ b/src/libraries/System.Speech/src/Internal/SrgsParser/XmlParser.cs @@ -168,7 +168,7 @@ internal static void ParseText(IElement parent, string sChars, string pronunciat } string sToken = sChars.Substring(i, iTokenEnd - i); - if (sToken.IndexOf('"') != -1) + if (sToken.Contains('"')) { // "The token string is not allowed to contain double quote character." XmlParser.ThrowSrgsException(SRID.InvalidTokenString); diff --git a/src/tasks/Crossgen2Tasks/RunReadyToRunCompiler.cs b/src/tasks/Crossgen2Tasks/RunReadyToRunCompiler.cs index 38ca23fedee837..ebd5b17ee8c922 100644 --- a/src/tasks/Crossgen2Tasks/RunReadyToRunCompiler.cs +++ b/src/tasks/Crossgen2Tasks/RunReadyToRunCompiler.cs @@ -397,7 +397,7 @@ protected override int ExecuteTool(string pathToTool, string responseFileCommand protected override void LogEventsFromTextOutput(string singleLine, MessageImportance messageImportance) { - if (!ShowCompilerWarnings && singleLine.IndexOf("warning:", StringComparison.OrdinalIgnoreCase) != -1) + if (!ShowCompilerWarnings && singleLine.Contains("warning:", StringComparison.OrdinalIgnoreCase)) { Log.LogMessage(MessageImportance.Normal, singleLine); WarningsDetected = true; diff --git a/src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs b/src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs index 423aa4a5561f6a..e520057d5b3bdf 100644 --- a/src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs +++ b/src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs @@ -274,7 +274,7 @@ private void UpdateAppRef(string sdkPath, string version) private string GetNuGetConfig() { string contents = File.ReadAllText(TemplateNuGetConfigPath); - if (contents.IndexOf(s_nugetInsertionTag, StringComparison.InvariantCultureIgnoreCase) < 0) + if (!contents.Contains(s_nugetInsertionTag, StringComparison.InvariantCultureIgnoreCase)) throw new LogAsErrorException($"Could not find {s_nugetInsertionTag} in {TemplateNuGetConfigPath}"); return contents.Replace(s_nugetInsertionTag, $@""); @@ -423,7 +423,7 @@ internal sealed record InstallWorkloadRequest( public string Version => Workload.GetMetadata("Version"); public string TargetPath => Target.GetMetadata("InstallPath"); public string StampPath => Target.GetMetadata("StampPath"); - public bool IgnoreErrors => Workload.GetMetadata("IgnoreErrors").ToLowerInvariant() == "true"; + public bool IgnoreErrors => Workload.GetMetadata("IgnoreErrors").Equals("true", StringComparison.InvariantCultureIgnoreCase); public string WorkloadId => Workload.ItemSpec; public bool Validate(TaskLoggingHelper log) diff --git a/src/tools/illink/src/linker/Linker.Steps/ProcessLinkerXmlBase.cs b/src/tools/illink/src/linker/Linker.Steps/ProcessLinkerXmlBase.cs index 12aff7c133ec15..e96ce5a22f5250 100644 --- a/src/tools/illink/src/linker/Linker.Steps/ProcessLinkerXmlBase.cs +++ b/src/tools/illink/src/linker/Linker.Steps/ProcessLinkerXmlBase.cs @@ -162,7 +162,7 @@ protected virtual void ProcessTypes (AssemblyDefinition assembly, XPathNavigator string fullname = GetFullName (typeNav); - if (fullname.IndexOf ("*") != -1) { + if (fullname.Contains ('*')) { if (ProcessTypePattern (fullname, assembly, typeNav)) continue; }