Skip to content

[StyleCleanUp] Specify StringComparison for correctness (CA1310) #10704

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/Microsoft.DotNet.Wpf/src/.editorconfig
Original file line number Diff line number Diff line change
@@ -38,9 +38,6 @@ dotnet_diagnostic.CA1067.severity = suggestion
# CA1070: Do not declare event fields as virtual
dotnet_diagnostic.CA1070.severity = suggestion

# CA1310: Specify StringComparison for correctness
dotnet_diagnostic.CA1310.severity = suggestion

# CA1419: Provide a parameterless constructor that is as visible as the containing type for concrete types derived from 'System.Runtime.InteropServices.SafeHandle'
dotnet_diagnostic.CA1419.severity = suggestion

Original file line number Diff line number Diff line change
@@ -153,7 +153,7 @@ public static (InspectableInfo inspectableInfo, List<ComInterfaceEntry> interfac

Type type = obj.GetType();

if (type.FullName.StartsWith("ABI."))
if (type.FullName.StartsWith("ABI.", StringComparison.Ordinal))
{
type = Projections.FindCustomPublicTypeForAbiType(type) ?? type.Assembly.GetType(type.FullName.Substring("ABI.".Length)) ?? type;
}
Original file line number Diff line number Diff line change
@@ -5,9 +5,10 @@

namespace WinRT
{

internal static class TypeExtensions
{
private const string NamespacePrefix = "MS.Internal.WindowsRuntime.";

public static Type FindHelperType(this Type type)
{
if (typeof(Exception).IsAssignableFrom(type))
@@ -19,12 +20,14 @@ public static Type FindHelperType(this Type type)
{
return customMapping;
}
var helper = $"ABI.{type.FullName}";

string helper = $"ABI.{type.FullName}";
string helperTypeName2 = $"MS.Internal.WindowsRuntime.ABI.{type.FullName}";
if (type.FullName.StartsWith("MS.Internal.WindowsRuntime."))
if (type.FullName.StartsWith(NamespacePrefix, StringComparison.Ordinal))
{
helper = $"MS.Internal.WindowsRuntime.ABI.{RemoveNamespacePrefix(type.FullName)}";
}

return Type.GetType(helper) ?? Type.GetType(helperTypeName2);
}

@@ -72,12 +75,7 @@ public static bool IsDelegate(this Type type)

public static string RemoveNamespacePrefix(string ns)
{
const string NamespacePrefix = "MS.Internal.WindowsRuntime.";
if (ns.StartsWith(NamespacePrefix))
{
return ns.Substring(NamespacePrefix.Length);
}
return ns;
return ns.StartsWith(NamespacePrefix, StringComparison.Ordinal) ? ns.Substring(NamespacePrefix.Length) : ns;
}
}
}
Original file line number Diff line number Diff line change
@@ -1115,7 +1115,7 @@ private void FormatCollectionChangedSource(int level, object source, bool? isLik

const string PublicKeyToken = "PublicKeyToken=";
string aqn = sourceType.AssemblyQualifiedName;
int index = aqn.LastIndexOf(PublicKeyToken);
int index = aqn.LastIndexOf(PublicKeyToken, StringComparison.Ordinal);
if (index >= 0)
{
ReadOnlySpan<char> token = aqn.AsSpan(index + PublicKeyToken.Length);
Original file line number Diff line number Diff line change
@@ -4829,7 +4829,7 @@ private static string DisplayType(object o)
}

string name = t.ToString();
isWPFControl = name.StartsWith("System.Windows.Controls.");
isWPFControl = name.StartsWith("System.Windows.Controls.", StringComparison.Ordinal);
if (isWPFControl)
{
name = name.Substring(24); // 24 == length of "s.w.c."
Original file line number Diff line number Diff line change
@@ -495,15 +495,16 @@ public override IEnumerable<MarkupObject> Items
Type keyType = GetDictionaryKeyType(dictionary);

// Attempt to emit the contents of the dictionary in a more deterministic
// order. This is not guarenteed to be deterministic because it uses ToString
// which is not guarenteed to be unique for each value. Keys with non-unique
// order. This is not guaranteed to be deterministic because it uses ToString
// which is not guaranteed to be unique for each value. Keys with non-unique
// ToString() values will not be emitted deterministically.
DictionaryEntry[] entries = new DictionaryEntry[dictionary.Count];
dictionary.CopyTo(entries, 0);
Array.Sort(entries, delegate(DictionaryEntry one, DictionaryEntry two)
Array.Sort(entries, static (DictionaryEntry one, DictionaryEntry two) =>
{
return String.Compare(one.Key.ToString(), two.Key.ToString());
return string.Compare(one.Key.ToString(), two.Key.ToString(), StringComparison.Ordinal);
});

foreach (DictionaryEntry entry in entries)
{
ElementMarkupObject subItem
Original file line number Diff line number Diff line change
@@ -1892,12 +1892,14 @@ private static bool IsProgmanWindow(NativeMethods.HWND hwnd)
{
while (hwnd != NativeMethods.HWND.NULL)
{
if (ProxyManager.GetClassName(hwnd).CompareTo("Progman") == 0)
if (ProxyManager.GetClassName(hwnd).Equals("Progman", StringComparison.Ordinal))
{
return true;
}

hwnd = SafeNativeMethods.GetAncestor(hwnd, SafeNativeMethods.GA_PARENT);
}

return false;
}

Original file line number Diff line number Diff line change
@@ -864,12 +864,14 @@ internal static bool IsProgmanWindow(IntPtr hwnd)
{
while (hwnd != IntPtr.Zero)
{
if (GetClassName(hwnd).CompareTo("Progman") == 0)
if (GetClassName(hwnd).Equals("Progman", StringComparison.Ordinal))
{
return true;
}

hwnd = NativeMethodsSetLastError.GetAncestor(hwnd, NativeMethods.GA_PARENT);
}

return false;
}