diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/ThunkedApis.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/ThunkedApis.cs index 092e91b63cb55..3e0765205c637 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/ThunkedApis.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/ThunkedApis.cs @@ -210,7 +210,7 @@ private static void SplitTypeName(string fullname, out string name, out string n Debug.Assert(fullname != null); // Get namespace - int nsDelimiter = fullname.LastIndexOf(".", StringComparison.Ordinal); + int nsDelimiter = fullname.LastIndexOf('.'); if (nsDelimiter != -1) { ns = fullname.Substring(0, nsDelimiter); diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/RuntimeMethodHelpers.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/RuntimeMethodHelpers.cs index 9ece9ba048a5c..13198f13979cf 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/RuntimeMethodHelpers.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/RuntimeMethodHelpers.cs @@ -78,7 +78,7 @@ internal static string ComputeParametersString(RuntimeParameterInfo[] parameters // Legacy: Why use "ByRef" for by ref parameters? What language is this? // VB uses "ByRef" but it should precede (not follow) the parameter name. // Why don't we just use "&"? - if (parameterTypeString.EndsWith("&")) + if (parameterTypeString.EndsWith('&')) { sb.Append(parameterTypeString, 0, parameterTypeString.Length - 1); sb.Append(" ByRef"); diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.GetMember.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.GetMember.cs index d0c82928f1928..e40e38faf10ea 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.GetMember.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.GetMember.cs @@ -29,7 +29,7 @@ public sealed override MemberInfo[] GetMember(string name, MemberTypes type, Bin private MemberInfo[] GetMemberImpl(string optionalNameOrPrefix, MemberTypes type, BindingFlags bindingAttr) { - bool prefixSearch = optionalNameOrPrefix != null && optionalNameOrPrefix.EndsWith("*", StringComparison.Ordinal); + bool prefixSearch = optionalNameOrPrefix != null && optionalNameOrPrefix.EndsWith('*'); string? optionalName = prefixSearch ? null : optionalNameOrPrefix; Func? predicate = null; diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/LocalAppContextSwitches.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/LocalAppContextSwitches.cs index 1da5480d9d70e..64fd325e8df25 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/LocalAppContextSwitches.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/LocalAppContextSwitches.cs @@ -18,21 +18,11 @@ private static bool InitializeDefaultActivityIdFormat() string? switchValue = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_DIAGNOSTICS_DEFAULTACTIVITYIDFORMATISHIERARCHIAL"); if (switchValue != null) { - defaultActivityIdFormatIsHierarchial = IsTrueStringIgnoreCase(switchValue) || switchValue.Equals("1"); + defaultActivityIdFormatIsHierarchial = switchValue.Equals("true", StringComparison.OrdinalIgnoreCase) || switchValue.Equals("1"); } } return defaultActivityIdFormatIsHierarchial; } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static bool IsTrueStringIgnoreCase(string value) - { - return value.Length == 4 && - (value[0] == 't' || value[0] == 'T') && - (value[1] == 'r' || value[1] == 'R') && - (value[2] == 'u' || value[2] == 'U') && - (value[3] == 'e' || value[3] == 'E'); - } } } diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Windows.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Windows.cs index d0eb17f573267..8c5614e5a0d01 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Windows.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Windows.cs @@ -527,7 +527,7 @@ private static ProcessInfo[] GetProcessInfos(PerformanceCounterLib library, int // at the end. If instanceName ends in ".", ".e", or ".ex" we remove it. if (instanceName.Length == 15) { - if (instanceName.EndsWith(".", StringComparison.Ordinal)) + if (instanceName.EndsWith(".")) { instanceName = instanceName.Slice(0, 14); } diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/FontConverter.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/FontConverter.cs index 1e2125a60a32c..3897358d9e37e 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/FontConverter.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/FontConverter.cs @@ -38,7 +38,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, [NotNullWhen( ValueStringBuilder sb = default; sb.Append(font.Name); sb.Append(culture.TextInfo.ListSeparator[0]); - sb.Append(" "); + sb.Append(' '); sb.Append(font.Size.ToString(culture.NumberFormat)); switch (font.Unit) diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/ServiceNameStore.cs b/src/libraries/System.Net.HttpListener/src/System/Net/ServiceNameStore.cs index 5decfe72c1aab..6656dc49cbcca 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/ServiceNameStore.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/ServiceNameStore.cs @@ -270,8 +270,8 @@ public static string[] BuildServiceNames(string uriPrefix) { string hostname = ExtractHostname(uriPrefix, true)!; - if (string.Equals(hostname, "*", StringComparison.OrdinalIgnoreCase) || - string.Equals(hostname, "+", StringComparison.OrdinalIgnoreCase) || + if (hostname == "*" || + hostname == "+" || IPAddress.TryParse(hostname, out _)) { // for a wildcard, register the machine name. If the caller doesn't have DNS permission diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs index 91f25c2f1a85e..5251c414d8ec4 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs @@ -1579,8 +1579,8 @@ private static void SendError(HttpListenerSession session, ulong requestId, Http httpResponse.pReason = (sbyte*)pReason; httpResponse.ReasonLength = (ushort)byteReason.Length; - byte[] byteContentLength = Encoding.Default.GetBytes("0"); - fixed (byte* pContentLength = &byteContentLength[0]) + ReadOnlySpan byteContentLength = "0"u8; + fixed (byte* pContentLength = byteContentLength) { (&httpResponse.Headers.KnownHeaders)[(int)HttpResponseHeader.ContentLength].pRawValue = (sbyte*)pContentLength; (&httpResponse.Headers.KnownHeaders)[(int)HttpResponseHeader.ContentLength].RawValueLength = (ushort)byteContentLength.Length; diff --git a/src/libraries/System.Private.CoreLib/src/System/AppContextConfigHelper.cs b/src/libraries/System.Private.CoreLib/src/System/AppContextConfigHelper.cs index 712f8973ca697..3a8c3e8e7ea72 100644 --- a/src/libraries/System.Private.CoreLib/src/System/AppContextConfigHelper.cs +++ b/src/libraries/System.Private.CoreLib/src/System/AppContextConfigHelper.cs @@ -88,7 +88,7 @@ internal static short GetInt16Config(string configName, short defaultValue, bool { result = Convert.ToInt16(str, 16); } - else if (str.StartsWith("0")) + else if (str.StartsWith('0')) { result = Convert.ToInt16(str, 8); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/LibraryNameVariation.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/LibraryNameVariation.Windows.cs index d320b03d75996..fe1782f0fc32f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/LibraryNameVariation.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/LibraryNameVariation.Windows.cs @@ -16,7 +16,7 @@ internal static IEnumerable DetermineLibraryNameVariations yield return new LibraryNameVariation(string.Empty, string.Empty); if (isRelativePath - && !libName.EndsWith(".", StringComparison.OrdinalIgnoreCase) + && !libName.EndsWith('.') && !libName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) && !libName.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) { diff --git a/src/libraries/System.Speech/src/Internal/SrgsParser/XmlParser.cs b/src/libraries/System.Speech/src/Internal/SrgsParser/XmlParser.cs index 8be029c4d4b14..79c87dfa6d34b 100644 --- a/src/libraries/System.Speech/src/Internal/SrgsParser/XmlParser.cs +++ b/src/libraries/System.Speech/src/Internal/SrgsParser/XmlParser.cs @@ -361,7 +361,7 @@ private void ParseGrammar(XmlReader reader, IGrammar grammar) catch (ArgumentException) { // Unknown Culture info, fall back to the base culture. - int pos = reader.Value.IndexOf("-", StringComparison.Ordinal); + int pos = reader.Value.IndexOf('-'); if (pos > 0) { grammar.Culture = _langId = new CultureInfo(reader.Value.Substring(0, pos)); @@ -1767,7 +1767,7 @@ private static void SetRepeatValues(string repeat, out int minRepeat, out int ma minRepeat = maxRepeat = 1; if (!string.IsNullOrEmpty(repeat)) { - int sep = repeat.IndexOf("-", StringComparison.Ordinal); + int sep = repeat.IndexOf('-'); if (sep < 0) { diff --git a/src/libraries/System.Speech/src/Internal/Synthesis/SSmlParser.cs b/src/libraries/System.Speech/src/Internal/Synthesis/SSmlParser.cs index f8122222920f0..1cc7e718a5e72 100644 --- a/src/libraries/System.Speech/src/Internal/Synthesis/SSmlParser.cs +++ b/src/libraries/System.Speech/src/Internal/Synthesis/SSmlParser.cs @@ -128,7 +128,7 @@ private static void ProcessSpeakElement(XmlReader reader, ISsmlParser engine, ob { innerException = e; // Unknown Culture info, fall back to the base culture. - int pos = reader.Value.IndexOf("-", StringComparison.Ordinal); + int pos = reader.Value.IndexOf('-'); if (pos > 0) { try diff --git a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs index 106879b21af80..6201c5d610bd2 100644 --- a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs @@ -162,7 +162,7 @@ private static void SplitName(string? fullname, out string? name, out string? ns return; // Get namespace - int nsDelimiter = fullname.LastIndexOf(".", StringComparison.Ordinal); + int nsDelimiter = fullname.LastIndexOf('.'); if (nsDelimiter != -1) { ns = fullname.Substring(0, nsDelimiter); @@ -236,7 +236,7 @@ private static void FilterHelper( listType = MemberListType.CaseSensitive; } - if (allowPrefixLookup && name.EndsWith("*", StringComparison.Ordinal)) + if (allowPrefixLookup && name.EndsWith('*')) { // We set prefixLookup to true if name ends with a "*". // We will also set listType to All so that all members are included in