From 6a75641e44e2cf5955ffdf11ac51623a95bf17c7 Mon Sep 17 00:00:00 2001 From: Himanshi Goyal Date: Thu, 5 Dec 2024 12:21:44 +0530 Subject: [PATCH 1/7] Resolving CA2249, CA2251, CA1847 CA1845 and CA1846 --- src/Microsoft.DotNet.Wpf/src/.editorconfig | 15 --------------- .../MS/Internal/MarkupCompiler/MarkupCompiler.cs | 2 +- .../MS/Internal/Tasks/TaskHelper.cs | 2 +- .../Microsoft/Build/Tasks/Windows/UidManager.cs | 6 +++++- .../MS/Internal/Data/RBNode.cs | 8 ++++---- .../MS/Internal/Data/RBTree.cs | 2 +- .../MS/Internal/Interop/InternalDispatchObject.cs | 2 +- .../System/Windows/Documents/XamlToRtfWriter.cs | 4 ++-- .../Windows/Markup/DependencyPropertyConverter.cs | 2 +- .../Windows/Markup/MarkupExtensionParser.cs | 11 +++++++++-- .../System/Windows/Markup/XamlReaderHelper.cs | 7 +++++-- .../Serialization/ColorTypeConverter.cs | 2 +- .../Serialization/VisualTreeFlattener.cs | 2 +- .../Ribbon/RibbonKeyTipAndContentSyncHelper.cs | 5 ++--- .../System/Xaml/Parser/GenericTypeNameParser.cs | 4 +--- .../MS/Internal/Automation/ProxyManager.cs | 4 ++-- .../Internal/AutomationProxies/WinFormsSpinner.cs | 4 ++-- .../AutomationProxies/WindowsContainer.cs | 2 +- .../MS/Internal/AutomationProxies/WindowsMenu.cs | 4 ++-- .../Internal/AutomationProxies/WindowsRichEdit.cs | 4 ++-- .../Internal/AutomationProxies/WindowsSpinner.cs | 4 ++-- .../AutomationProxies/WindowsSysHeader.cs | 4 ++-- .../Internal/AutomationProxies/WindowsUpDown.cs | 2 +- .../src/WindowsBase/MS/Internal/AvTrace.cs | 4 ++-- .../Packaging/CompoundFile/ContainerUtilities.cs | 2 +- .../MS/Internal/IO/Packaging/PackUriHelper.cs | 2 +- 26 files changed, 53 insertions(+), 57 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/.editorconfig b/src/Microsoft.DotNet.Wpf/src/.editorconfig index 27d970fb0af..b7e496ef43f 100644 --- a/src/Microsoft.DotNet.Wpf/src/.editorconfig +++ b/src/Microsoft.DotNet.Wpf/src/.editorconfig @@ -105,15 +105,6 @@ dotnet_diagnostic.CA1834.severity = suggestion # CA1838: Avoid StringBuilder parameters for P/Invokes dotnet_diagnostic.CA1838.severity = suggestion -# CA1845: Use span-based 'string.Concat' -dotnet_diagnostic.CA1845.severity = suggestion - -# CA1846: Prefer AsSpan over Substring -dotnet_diagnostic.CA1846.severity = suggestion - -# CA1847: Use string.Contains(char) instead of string.Contains(string) with single characters -dotnet_diagnostic.CA1847.severity = suggestion - # CA1851: Possible multiple enumerations of IEnumerable collection dotnet_diagnostic.CA1851.severity = suggestion @@ -161,12 +152,6 @@ dotnet_diagnostic.CA2219.severity = suggestion # CA2242: Test for NaN correctly dotnet_diagnostic.CA2242.severity = suggestion -# CA2249: Consider using 'string.Contains' instead of 'string.IndexOf' -dotnet_diagnostic.CA2249.severity = suggestion - -# CA2251: Use String.Equals over String.Compare -dotnet_diagnostic.CA2251.severity = suggestion - # CA2300: Do not use insecure deserializer BinaryFormatter dotnet_diagnostic.CA2300.severity = suggestion diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs index 8b24771d9e6..9293cd8ba22 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs @@ -483,7 +483,7 @@ private void Initialize(FileUnit sourceFile) } int pathEndIndex = SourceFileInfo.RelativeSourceFilePath.LastIndexOf(Path.DirectorySeparatorChar); - string targetPath = TargetPath + SourceFileInfo.RelativeSourceFilePath.Substring(0, pathEndIndex + 1); + string targetPath = string.Concat(TargetPath, SourceFileInfo.RelativeSourceFilePath.Substring(0, pathEndIndex + 1)); // Create if not already exists if (targetPath.Length > 0 && !Directory.Exists(targetPath)) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs index 0ca5ca94057..c31eddb8080 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs @@ -203,7 +203,7 @@ internal static string GetWholeExceptionMessage(Exception exception) while (e.InnerException != null) { Exception eInner = e.InnerException; - if (e.Message.IndexOf(eInner.Message, StringComparison.Ordinal) == -1) + if (!e.Message.Contains(eInner.Message)) { message += ", "; message += eInner.Message; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs index 1df5ea917cd..4d4384ad6e5 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs @@ -518,7 +518,11 @@ private UidCollector ParseFile(string fileName) collector.RootElementLinePosition = reader.LinePosition; } - if (reader.Name.IndexOf('.') >= 0) +#if NET + if (reader.Name.Contains('.')) +#else + if (reader.Name.Contains(".")) +#endif { // the name has a dot, which suggests it is a property tag. // we will ignore adding uid diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/RBNode.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/RBNode.cs index 7306f3519ad..476b3b0cc94 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/RBNode.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/RBNode.cs @@ -822,21 +822,21 @@ protected RBNode LoadTree(ref string s) s = s.Substring(1); index = s.IndexOf(','); // read LeftSize - node.LeftSize = Int32.Parse(s.Substring(0, index), TypeConverterHelper.InvariantEnglishUS); + node.LeftSize = Int32.Parse(s.AsSpan(0, index), TypeConverterHelper.InvariantEnglishUS); s = s.Substring(index + 1); index = s.IndexOf(','); // read Size - node.Size = Int32.Parse(s.Substring(0, index), TypeConverterHelper.InvariantEnglishUS); + node.Size = Int32.Parse(s.AsSpan(0, index), TypeConverterHelper.InvariantEnglishUS); s = s.Substring(index+1); for (int k = 0; k < node.Size-1; ++k) // read data { index = s.IndexOf(','); - node.SetItemAt(k, AsT(Int32.Parse(s.Substring(0, index), TypeConverterHelper.InvariantEnglishUS))); + node.SetItemAt(k, AsT(Int32.Parse(s.AsSpan(0, index), TypeConverterHelper.InvariantEnglishUS))); s = s.Substring(index+1); } index = s.IndexOf('('); - node.SetItemAt(node.Size - 1, AsT(Int32.Parse(s.Substring(0, index), TypeConverterHelper.InvariantEnglishUS))); + node.SetItemAt(node.Size - 1, AsT(Int32.Parse(s.AsSpan(0, index), TypeConverterHelper.InvariantEnglishUS))); s = s.Substring(index); node.LeftChild = LoadTree(ref s); // read subtrees diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/RBTree.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/RBTree.cs index 2db5f8b92b9..473264fe150 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/RBTree.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/RBTree.cs @@ -659,7 +659,7 @@ public void LoadTree(string s) { if (s.StartsWith("\"", StringComparison.Ordinal)) s = s.Substring(1); int index = s.IndexOf('('); - LeftSize = Int32.Parse(s.Substring(0, index), TypeConverterHelper.InvariantEnglishUS); + LeftSize = Int32.Parse(s.AsSpan(0, index), TypeConverterHelper.InvariantEnglishUS); s = s.Substring(index); this.LeftChild = LoadTree(ref s); this.LeftChild.Parent = this; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Interop/InternalDispatchObject.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Interop/InternalDispatchObject.cs index 48cf3a6ced8..2040470a2da 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Interop/InternalDispatchObject.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Interop/InternalDispatchObject.cs @@ -119,7 +119,7 @@ object IReflect.InvokeMember(string name, BindingFlags invokeAttr, Binder binder // We never expect to get a real method name here--see the explanation in GetMethods(). if (name.StartsWith("[DISPID=", StringComparison.OrdinalIgnoreCase)) { - int dispid = int.Parse(name.Substring(8, name.Length-9), CultureInfo.InvariantCulture); + int dispid = int.Parse(name.AsSpan(8, name.Length-9), CultureInfo.InvariantCulture); MethodInfo method; if (_dispId2MethodMap.TryGetValue(dispid, out method)) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XamlToRtfWriter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XamlToRtfWriter.cs index a489eb12287..fc28961d182 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XamlToRtfWriter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XamlToRtfWriter.cs @@ -3672,11 +3672,11 @@ ref StrikeState strikeState { ulState = ULState.ULNone; strikeState = StrikeState.StrikeNone; - if (decoration.IndexOf("Underline", StringComparison.OrdinalIgnoreCase) != -1) + if (decoration.Contains("Underline")) { ulState = ULState.ULNormal; } - if (decoration.IndexOf("Strikethrough", StringComparison.OrdinalIgnoreCase) != -1) + if (decoration.Contains("Strikethrough")) { strikeState = StrikeState.StrikeNormal; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/DependencyPropertyConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/DependencyPropertyConverter.cs index 1d76ee3b234..a92e964044d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/DependencyPropertyConverter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/DependencyPropertyConverter.cs @@ -142,7 +142,7 @@ internal static DependencyProperty ResolveProperty(IServiceProvider serviceProvi { value = value.Trim(); // If it contains a . it means that it is a full name with type and property. - if (value.Contains(".")) + if (value.Contains('.')) { // Prefixes could have .'s so we take the last one and do a type resolve against that int lastIndex = value.LastIndexOf('.'); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs index 83affcc2425..24e3c0e6f22 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs @@ -1465,8 +1465,11 @@ private string ResolveAttributeNamespaceURI(string prefix, string name, string p // if the prefix was "" then // 1) normal properties resolve to the parent Tag namespace. // 2) Attached properties resolve to the "" default namespace. - int dotIndex = name.IndexOf('.'); - if (-1 == dotIndex) +#if NET + if (!name.Contains('.')) +#else + if (!name.Contains(".")) +#endif attribNamespaceURI = parentURI; else attribNamespaceURI = _parserHelper.LookupNamespace(""); @@ -1625,7 +1628,11 @@ internal static void RemoveEscapes(ref string value) if (builder == null) { builder = new StringBuilder(value.Length); +#if NET + builder.Append(value.AsSpan(0,i)); +#else builder.Append(value.Substring(0,i)); +#endif } noEscape = false; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs index 02290ef67c3..5242910d2db 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs @@ -2738,8 +2738,11 @@ private string ResolveAttributeNamespaceURI(string prefix, string name, string p // if the prefix was "" then // 1) normal properties resolve to the parent Tag namespace. // 2) Attached properties resolve to the "" default namespace. - int dotIndex = name.IndexOf('.'); - if (-1 == dotIndex) +#if NET + if (!name.Contains('.')) +#else + if (!name.Contains(".")) +#endif attribNamespaceURI = parentURI; else attribNamespaceURI = XmlReader.LookupNamespace(""); diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/ColorTypeConverter.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/ColorTypeConverter.cs index 1a7d314aceb..ef0ed3718af 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/ColorTypeConverter.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/ColorTypeConverter.cs @@ -160,7 +160,7 @@ Type destinationType { colorString = color.ToString(culture); - if (colorString.StartsWith("sc#", StringComparison.Ordinal) && colorString.Contains("E")) + if (colorString.StartsWith("sc#", StringComparison.Ordinal) && colorString.Contains('E')) { // // Fix bug 1588888: Serialization produces non-compliant scRGB color string. diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/VisualTreeFlattener.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/VisualTreeFlattener.cs index 10583b6d1f8..009379dd361 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/VisualTreeFlattener.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/VisualTreeFlattener.cs @@ -148,7 +148,7 @@ Type destinationType index = m_mainFile.Length; } - string uri = m_mainFile.Substring(0, index) + "_" + bitmapName; + string uri = string.Concat(m_mainFile.Substring(0, index), "_", bitmapName); Stream bitmapStreamDest = new System.IO.FileStream(uri, FileMode.Create, FileAccess.ReadWrite, FileShare.None); diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonKeyTipAndContentSyncHelper.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonKeyTipAndContentSyncHelper.cs index ec140fe8662..de5e9982359 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonKeyTipAndContentSyncHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonKeyTipAndContentSyncHelper.cs @@ -46,8 +46,7 @@ public static void Sync(ISyncKeyTipAndContent syncElement, DependencyProperty co { if (accessKeyIndex == -1) { - int accessorIndex = stringContent.IndexOf(keyTip[0]); - if (accessorIndex != -1) + if (stringContent.Contains(keyTip[0])) { syncElement.KeepKeyTipAndContentInSync = true; syncElement.IsKeyTipSyncSource = true; @@ -155,7 +154,7 @@ public static object CoerceContentProperty(ISyncKeyTipAndContent syncElement, if (accessorIndex >= 0) { syncElement.KeepKeyTipAndContentInSync = true; - return stringContent.Substring(0, accessorIndex) + '_' + stringContent.Substring(accessorIndex); + return string.Concat(stringContent.Substring(0, accessorIndex), '_', stringContent.Substring(accessorIndex)); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/GenericTypeNameParser.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/GenericTypeNameParser.cs index 34e7d62db21..1417ffde594 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/GenericTypeNameParser.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/GenericTypeNameParser.cs @@ -40,9 +40,7 @@ public GenericTypeNameParser(Func prefixResolver) public static XamlTypeName ParseIfTrivalName(string text, Func prefixResolver, out string error) { - int parenIdx = text.IndexOf('('); - int bracketIdx = text.IndexOf('['); - if (parenIdx != -1 || bracketIdx != -1) + if (text.Contains('(') || text.Contains('[')) { error = string.Empty; return null; diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ProxyManager.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ProxyManager.cs index 8ab70515bf2..8e7af90ccf3 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ProxyManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ProxyManager.cs @@ -671,14 +671,14 @@ static private IRawElementProviderSimple GetProxyFromEntry(ProxyScoping findType break; case ProxyScoping.PartialMatchApparentClassName: - if (classNameForPartialMatch.IndexOf(pi.ClassName, StringComparison.Ordinal) >= 0) + if (classNameForPartialMatch.Contains(pi.ClassName)) { factoryCallback = pi.ClientSideProviderFactoryCallback; } break; case ProxyScoping.PartialMatchRealClassName: - if (classNameForPartialMatch.IndexOf(pi.ClassName, StringComparison.Ordinal) >= 0 + if (classNameForPartialMatch.Contains(pi.ClassName) && ((pi.Flags & ClientSideProviderMatchIndicator.DisallowBaseClassNameMatch) == 0)) { factoryCallback = pi.ClientSideProviderFactoryCallback; diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinFormsSpinner.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinFormsSpinner.cs index 9b1dcf4280e..80f83ba758d 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinFormsSpinner.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinFormsSpinner.cs @@ -154,7 +154,7 @@ internal static IRawElementProviderSimple Create(IntPtr hwnd, int idChild) IntPtr hwndSpin; // Find the Edit control. Typically the UpDown is first so we'll start with the other window. - if (Misc.ProxyGetClassName(hwndLastChild).IndexOf("Edit", StringComparison.OrdinalIgnoreCase) != -1) + if (Misc.ProxyGetClassName(hwndLastChild).Contains("Edit")) { hwndEdit = hwndLastChild; hwndSpin = hwndFirstChild; @@ -162,7 +162,7 @@ internal static IRawElementProviderSimple Create(IntPtr hwnd, int idChild) else { // Haven't seen this but suppose it's possible. Subsequent test will confirm. - if (Misc.ProxyGetClassName(hwndFirstChild).IndexOf("Edit", StringComparison.OrdinalIgnoreCase) != -1) + if (Misc.ProxyGetClassName(hwndFirstChild).Contains("Edit")) { hwndEdit = hwndFirstChild; hwndSpin = hwndLastChild; diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsContainer.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsContainer.cs index 3133253b940..b24eeecd683 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsContainer.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsContainer.cs @@ -37,7 +37,7 @@ public WindowsContainer (IntPtr hwnd, ProxyHwnd parent, int item) { _sType = SR.LocalizedControlTypeDialog; } - else if (className.IndexOf("AfxControlBar", StringComparison.Ordinal) != -1) + else if (className.Contains("AfxControlBar")) { _sType = SR.LocalizedControlTypeContainer; } diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsMenu.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsMenu.cs index 4f16c7d5a81..d676bf3fc19 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsMenu.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsMenu.cs @@ -2460,7 +2460,7 @@ private static string AccelatorKeyCtrl(string sKeyword, string sCanonicalsKeywor { // Take the remaining string from the Keyword // Case Alt+Enter - return sCanonicalsKeyword + menuRawText.Substring(pos + cKeyChars + 1, cMenuChars - (pos + cKeyChars + 1)); + return string.Concat(sCanonicalsKeyword, menuRawText.Substring(pos + cKeyChars + 1, cMenuChars - (pos + cKeyChars + 1))); } } } @@ -2482,7 +2482,7 @@ private static string AccelatorFxx (string menuText) // Check that it is the form Fxx if (pos < cChars - 1 && pos > 0 && menuText [pos] == 'f') { - int iKey = int.Parse(menuText.Substring(pos + 1, cChars - (pos + 1)), CultureInfo.InvariantCulture); + int iKey = int.Parse(menuText.AsSpan(pos + 1, cChars - (pos + 1)), CultureInfo.InvariantCulture); if (iKey > 0 && iKey <= 12) { return "F" + iKey.ToString(CultureInfo.CurrentCulture); diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsRichEdit.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsRichEdit.cs index ecd9e85cef0..a4d38987da8 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsRichEdit.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsRichEdit.cs @@ -534,7 +534,7 @@ private string GetValue() object embeddedObject; while (start < end && embeddedObjectOffset != -1) { - sbText.Append(text.Substring(start, embeddedObjectOffset - start)); + sbText.Append(text.AsSpan(start, embeddedObjectOffset - start)); range.SetRange(embeddedObjectOffset, end); if (range.GetEmbeddedObject(out embeddedObject) == NativeMethods.S_OK && embeddedObject != null) { @@ -552,7 +552,7 @@ private string GetValue() if (start < end) { - sbText.Append(text.Substring(start, end - start)); + sbText.Append(text.AsSpan(start, end - start)); } text = sbText.ToString(); diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSpinner.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSpinner.cs index c26117a2216..6ccbdc0acb4 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSpinner.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSpinner.cs @@ -67,7 +67,7 @@ internal static IRawElementProviderSimple Create(IntPtr hwnd, int idChild) return null; } - if (Misc.ProxyGetClassName(hwndBuddy).IndexOf("EDIT", StringComparison.OrdinalIgnoreCase) == -1) + if (!Misc.ProxyGetClassName(hwndBuddy).Contains("EDIT")) { return null; } @@ -281,7 +281,7 @@ internal static IntPtr GetUpDownFromEdit(IntPtr hwnd) while (hwndChild != IntPtr.Zero) { string className = Misc.ProxyGetClassName(hwndChild); - if (className.IndexOf("msctls_updown32", StringComparison.OrdinalIgnoreCase) != -1) + if (className.Contains("msctls_updown32")) { IntPtr hwndBuddy = Misc.ProxySendMessage(hwndChild, NativeMethods.UDM_GETBUDDY, IntPtr.Zero, IntPtr.Zero); if (hwnd == hwndBuddy) diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSysHeader.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSysHeader.cs index b09053b8ddd..832085570e5 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSysHeader.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSysHeader.cs @@ -80,7 +80,7 @@ internal static void RaiseEvents (IntPtr hwnd, int eventId, object idProp, int i IntPtr hwndParent = NativeMethodsSetLastError.GetAncestor (hwnd, NativeMethods.GA_PARENT); if (hwndParent != IntPtr.Zero) { - if (Misc.GetClassName(hwndParent).IndexOf("SysListView32", StringComparison.Ordinal) >= 0) + if (Misc.GetClassName(hwndParent).Contains("SysListView32")) { // Notify the Listview that the header Change WindowsListView wlv = (WindowsListView) WindowsListView.Create (hwndParent, 0); @@ -251,7 +251,7 @@ internal void ScrollIntoView(HeaderItem headerItem) IntPtr hwndParent = NativeMethodsSetLastError.GetAncestor (_hwnd, NativeMethods.GA_PARENT); if (hwndParent != IntPtr.Zero) { - if (Misc.GetClassName(hwndParent).IndexOf("SysListView32", StringComparison.Ordinal) >= 0) + if (Misc.GetClassName(hwndParent).Contains("SysListView32")) { // Determine the number of pixels or columns to scroll horizontally. int pixels = 0; diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsUpDown.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsUpDown.cs index 6d2ad57eddf..d35876ce984 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsUpDown.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsUpDown.cs @@ -373,7 +373,7 @@ private bool IsSpinnerElement() // If this is a Spinner UpDown Control, the buddy window should be a control with // the class of EDIT. IntPtr hwndBuddy = HwndBuddy(_hwnd); - return hwndBuddy != IntPtr.Zero && Misc.ProxyGetClassName(hwndBuddy).IndexOf("EDIT", StringComparison.OrdinalIgnoreCase) != -1; + return hwndBuddy != IntPtr.Zero && Misc.ProxyGetClassName(hwndBuddy).Contains("EDIT"); } private double Max diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/AvTrace.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/AvTrace.cs index 8bb1e7a8b41..9fcf8092082 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/AvTrace.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/AvTrace.cs @@ -419,7 +419,7 @@ static public string AntiFormat(string s) else { // duplicate the formatting character - sb.Append(s.Substring(index, formatIndex - index + 1)); + sb.Append(s.AsSpan(index, formatIndex - index + 1)); sb.Append(s[formatIndex]); index = formatIndex + 1; @@ -429,7 +429,7 @@ static public string AntiFormat(string s) if (index <= lengthMinus1) { - sb.Append(s.Substring(index)); + sb.Append(s.AsSpan(index)); } return sb.ToString(); diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs index 4fee4453460..a165c672781 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs @@ -459,7 +459,7 @@ static internal void CheckStringForEmbeddedPathSeparator(string testString, { CheckStringAgainstNullAndEmpty(testString, testStringIdentifier); - if (testString.IndexOf(PathSeparator) != -1) + if (testString.Contains(PathSeparator)) throw new ArgumentException( SR.Format(SR.NameCanNotHaveDelimiter, testStringIdentifier, diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/PackUriHelper.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/PackUriHelper.cs index 9d61276a767..7f4b133f628 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/PackUriHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/PackUriHelper.cs @@ -60,7 +60,7 @@ internal static Uri PackageRootUri internal static bool IsPackUri(Uri uri) { return uri != null && - string.Compare(uri.Scheme, System.IO.Packaging.PackUriHelper.UriSchemePack, StringComparison.OrdinalIgnoreCase) == 0; + string.Equals(uri.Scheme, System.IO.Packaging.PackUriHelper.UriSchemePack, StringComparison.OrdinalIgnoreCase); } /// From 2c9add8f19ea23a09ae0d05773d0138e5bf2cd6b Mon Sep 17 00:00:00 2001 From: Himanshi Goyal Date: Fri, 6 Dec 2024 12:07:55 +0530 Subject: [PATCH 2/7] Adding String Comparison to Contains Check --- .../PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs | 2 +- .../System/Windows/Documents/XamlToRtfWriter.cs | 4 ++-- .../UIAutomationClient/MS/Internal/Automation/ProxyManager.cs | 4 ++-- .../MS/Internal/AutomationProxies/WinFormsSpinner.cs | 4 ++-- .../MS/Internal/AutomationProxies/WindowsContainer.cs | 2 +- .../MS/Internal/AutomationProxies/WindowsSpinner.cs | 4 ++-- .../MS/Internal/AutomationProxies/WindowsSysHeader.cs | 4 ++-- .../MS/Internal/AutomationProxies/WindowsUpDown.cs | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs index c31eddb8080..964336c7110 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs @@ -203,7 +203,7 @@ internal static string GetWholeExceptionMessage(Exception exception) while (e.InnerException != null) { Exception eInner = e.InnerException; - if (!e.Message.Contains(eInner.Message)) + if (!e.Message.Contains(eInner.Message, StringComparison.Ordinal)) { message += ", "; message += eInner.Message; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XamlToRtfWriter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XamlToRtfWriter.cs index fc28961d182..907068e9921 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XamlToRtfWriter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XamlToRtfWriter.cs @@ -3672,11 +3672,11 @@ ref StrikeState strikeState { ulState = ULState.ULNone; strikeState = StrikeState.StrikeNone; - if (decoration.Contains("Underline")) + if (decoration.Contains("Underline", StringComparison.OrdinalIgnoreCase)) { ulState = ULState.ULNormal; } - if (decoration.Contains("Strikethrough")) + if (decoration.Contains("Strikethrough", StringComparison.OrdinalIgnoreCase)) { strikeState = StrikeState.StrikeNormal; } diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ProxyManager.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ProxyManager.cs index 8e7af90ccf3..ae5f84567e0 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ProxyManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ProxyManager.cs @@ -671,14 +671,14 @@ static private IRawElementProviderSimple GetProxyFromEntry(ProxyScoping findType break; case ProxyScoping.PartialMatchApparentClassName: - if (classNameForPartialMatch.Contains(pi.ClassName)) + if (classNameForPartialMatch.Contains(pi.ClassName, StringComparison.Ordinal)) { factoryCallback = pi.ClientSideProviderFactoryCallback; } break; case ProxyScoping.PartialMatchRealClassName: - if (classNameForPartialMatch.Contains(pi.ClassName) + if (classNameForPartialMatch.Contains(pi.ClassName, StringComparison.Ordinal) && ((pi.Flags & ClientSideProviderMatchIndicator.DisallowBaseClassNameMatch) == 0)) { factoryCallback = pi.ClientSideProviderFactoryCallback; diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinFormsSpinner.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinFormsSpinner.cs index 80f83ba758d..cef4cc5d046 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinFormsSpinner.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinFormsSpinner.cs @@ -154,7 +154,7 @@ internal static IRawElementProviderSimple Create(IntPtr hwnd, int idChild) IntPtr hwndSpin; // Find the Edit control. Typically the UpDown is first so we'll start with the other window. - if (Misc.ProxyGetClassName(hwndLastChild).Contains("Edit")) + if (Misc.ProxyGetClassName(hwndLastChild).Contains("Edit", StringComparison.OrdinalIgnoreCase)) { hwndEdit = hwndLastChild; hwndSpin = hwndFirstChild; @@ -162,7 +162,7 @@ internal static IRawElementProviderSimple Create(IntPtr hwnd, int idChild) else { // Haven't seen this but suppose it's possible. Subsequent test will confirm. - if (Misc.ProxyGetClassName(hwndFirstChild).Contains("Edit")) + if (Misc.ProxyGetClassName(hwndFirstChild).Contains("Edit", StringComparison.OrdinalIgnoreCase)) { hwndEdit = hwndFirstChild; hwndSpin = hwndLastChild; diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsContainer.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsContainer.cs index b24eeecd683..6ac47701634 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsContainer.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsContainer.cs @@ -37,7 +37,7 @@ public WindowsContainer (IntPtr hwnd, ProxyHwnd parent, int item) { _sType = SR.LocalizedControlTypeDialog; } - else if (className.Contains("AfxControlBar")) + else if (className.Contains("AfxControlBar", StringComparison.Ordinal)) { _sType = SR.LocalizedControlTypeContainer; } diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSpinner.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSpinner.cs index 6ccbdc0acb4..c8011128a1c 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSpinner.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSpinner.cs @@ -67,7 +67,7 @@ internal static IRawElementProviderSimple Create(IntPtr hwnd, int idChild) return null; } - if (!Misc.ProxyGetClassName(hwndBuddy).Contains("EDIT")) + if (!Misc.ProxyGetClassName(hwndBuddy).Contains("EDIT", StringComparison.OrdinalIgnoreCase)) { return null; } @@ -281,7 +281,7 @@ internal static IntPtr GetUpDownFromEdit(IntPtr hwnd) while (hwndChild != IntPtr.Zero) { string className = Misc.ProxyGetClassName(hwndChild); - if (className.Contains("msctls_updown32")) + if (className.Contains("msctls_updown32", StringComparison.OrdinalIgnoreCase)) { IntPtr hwndBuddy = Misc.ProxySendMessage(hwndChild, NativeMethods.UDM_GETBUDDY, IntPtr.Zero, IntPtr.Zero); if (hwnd == hwndBuddy) diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSysHeader.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSysHeader.cs index 832085570e5..8aad615f4f9 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSysHeader.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSysHeader.cs @@ -80,7 +80,7 @@ internal static void RaiseEvents (IntPtr hwnd, int eventId, object idProp, int i IntPtr hwndParent = NativeMethodsSetLastError.GetAncestor (hwnd, NativeMethods.GA_PARENT); if (hwndParent != IntPtr.Zero) { - if (Misc.GetClassName(hwndParent).Contains("SysListView32")) + if (Misc.GetClassName(hwndParent).Contains("SysListView32", StringComparison.Ordinal)) { // Notify the Listview that the header Change WindowsListView wlv = (WindowsListView) WindowsListView.Create (hwndParent, 0); @@ -251,7 +251,7 @@ internal void ScrollIntoView(HeaderItem headerItem) IntPtr hwndParent = NativeMethodsSetLastError.GetAncestor (_hwnd, NativeMethods.GA_PARENT); if (hwndParent != IntPtr.Zero) { - if (Misc.GetClassName(hwndParent).Contains("SysListView32")) + if (Misc.GetClassName(hwndParent).Contains("SysListView32", StringComparison.Ordinal)) { // Determine the number of pixels or columns to scroll horizontally. int pixels = 0; diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsUpDown.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsUpDown.cs index d35876ce984..d63219958d3 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsUpDown.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsUpDown.cs @@ -373,7 +373,7 @@ private bool IsSpinnerElement() // If this is a Spinner UpDown Control, the buddy window should be a control with // the class of EDIT. IntPtr hwndBuddy = HwndBuddy(_hwnd); - return hwndBuddy != IntPtr.Zero && Misc.ProxyGetClassName(hwndBuddy).Contains("EDIT"); + return hwndBuddy != IntPtr.Zero && Misc.ProxyGetClassName(hwndBuddy).Contains("EDIT", StringComparison.OrdinalIgnoreCase); } private double Max From 69ae62b871a4eaa97f81ef752ac3a92c5942690f Mon Sep 17 00:00:00 2001 From: Himanshi Goyal Date: Fri, 6 Dec 2024 15:58:11 +0530 Subject: [PATCH 3/7] Adding the NET check --- .../PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs index 964336c7110..7b58153636d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs @@ -203,7 +203,11 @@ internal static string GetWholeExceptionMessage(Exception exception) while (e.InnerException != null) { Exception eInner = e.InnerException; +#if NET if (!e.Message.Contains(eInner.Message, StringComparison.Ordinal)) +#else + if (e.Message.IndexOf(eInner.Message, StringComparison.Ordinal) == -1) +#endif { message += ", "; message += eInner.Message; From 753cd86152b3547e63455c59f3943017a2b158ef Mon Sep 17 00:00:00 2001 From: Himanshi Goyal Date: Tue, 7 Jan 2025 19:24:53 +0530 Subject: [PATCH 4/7] Removing NET check --- .../MS/Internal/Tasks/TaskHelper.cs | 6 ++---- .../Microsoft/Build/Tasks/Windows/UidManager.cs | 6 ++---- .../System/Windows/Markup/MarkupExtensionParser.cs | 12 ++++-------- .../System/Windows/Markup/XamlReaderHelper.cs | 6 ++---- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs index 7b58153636d..960e3deca0d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs @@ -203,11 +203,9 @@ internal static string GetWholeExceptionMessage(Exception exception) while (e.InnerException != null) { Exception eInner = e.InnerException; -#if NET - if (!e.Message.Contains(eInner.Message, StringComparison.Ordinal)) -#else +#pragma warning disable CA2249 if (e.Message.IndexOf(eInner.Message, StringComparison.Ordinal) == -1) -#endif +#pragma warning restore CA2249 { message += ", "; message += eInner.Message; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs index 4d4384ad6e5..47484ff4e16 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs @@ -518,11 +518,9 @@ private UidCollector ParseFile(string fileName) collector.RootElementLinePosition = reader.LinePosition; } -#if NET - if (reader.Name.Contains('.')) -#else +#pragma warning disable CA1847 if (reader.Name.Contains(".")) -#endif +#pragma warning restore CA1847 { // the name has a dot, which suggests it is a property tag. // we will ignore adding uid diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs index 24e3c0e6f22..447b30ae5e2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs @@ -1465,11 +1465,9 @@ private string ResolveAttributeNamespaceURI(string prefix, string name, string p // if the prefix was "" then // 1) normal properties resolve to the parent Tag namespace. // 2) Attached properties resolve to the "" default namespace. -#if NET - if (!name.Contains('.')) -#else +#pragma warning disable CA1847 if (!name.Contains(".")) -#endif +#pragma warning restore CA1847 attribNamespaceURI = parentURI; else attribNamespaceURI = _parserHelper.LookupNamespace(""); @@ -1628,11 +1626,9 @@ internal static void RemoveEscapes(ref string value) if (builder == null) { builder = new StringBuilder(value.Length); -#if NET - builder.Append(value.AsSpan(0,i)); -#else +#pragma warning disable CA1846 builder.Append(value.Substring(0,i)); -#endif +#pragma warning restore CA1846 } noEscape = false; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs index 5242910d2db..d5a32cb40a3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs @@ -2738,11 +2738,9 @@ private string ResolveAttributeNamespaceURI(string prefix, string name, string p // if the prefix was "" then // 1) normal properties resolve to the parent Tag namespace. // 2) Attached properties resolve to the "" default namespace. -#if NET - if (!name.Contains('.')) -#else +#pragma warning disable CA1847 if (!name.Contains(".")) -#endif +#pragma warning restore CA1847 attribNamespaceURI = parentURI; else attribNamespaceURI = XmlReader.LookupNamespace(""); From 6665d3e9c3c1c484b2da94aea7c6eaf0197abaad Mon Sep 17 00:00:00 2001 From: Himanshi Goyal Date: Mon, 3 Feb 2025 11:34:21 +0530 Subject: [PATCH 5/7] Revert "Removing NET check" This reverts commit 753cd86152b3547e63455c59f3943017a2b158ef. --- .../MS/Internal/Tasks/TaskHelper.cs | 6 ++++-- .../Microsoft/Build/Tasks/Windows/UidManager.cs | 6 ++++-- .../System/Windows/Markup/MarkupExtensionParser.cs | 12 ++++++++---- .../System/Windows/Markup/XamlReaderHelper.cs | 6 ++++-- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs index 960e3deca0d..7b58153636d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs @@ -203,9 +203,11 @@ internal static string GetWholeExceptionMessage(Exception exception) while (e.InnerException != null) { Exception eInner = e.InnerException; -#pragma warning disable CA2249 +#if NET + if (!e.Message.Contains(eInner.Message, StringComparison.Ordinal)) +#else if (e.Message.IndexOf(eInner.Message, StringComparison.Ordinal) == -1) -#pragma warning restore CA2249 +#endif { message += ", "; message += eInner.Message; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs index 47484ff4e16..4d4384ad6e5 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs @@ -518,9 +518,11 @@ private UidCollector ParseFile(string fileName) collector.RootElementLinePosition = reader.LinePosition; } -#pragma warning disable CA1847 +#if NET + if (reader.Name.Contains('.')) +#else if (reader.Name.Contains(".")) -#pragma warning restore CA1847 +#endif { // the name has a dot, which suggests it is a property tag. // we will ignore adding uid diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs index 447b30ae5e2..24e3c0e6f22 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs @@ -1465,9 +1465,11 @@ private string ResolveAttributeNamespaceURI(string prefix, string name, string p // if the prefix was "" then // 1) normal properties resolve to the parent Tag namespace. // 2) Attached properties resolve to the "" default namespace. -#pragma warning disable CA1847 +#if NET + if (!name.Contains('.')) +#else if (!name.Contains(".")) -#pragma warning restore CA1847 +#endif attribNamespaceURI = parentURI; else attribNamespaceURI = _parserHelper.LookupNamespace(""); @@ -1626,9 +1628,11 @@ internal static void RemoveEscapes(ref string value) if (builder == null) { builder = new StringBuilder(value.Length); -#pragma warning disable CA1846 +#if NET + builder.Append(value.AsSpan(0,i)); +#else builder.Append(value.Substring(0,i)); -#pragma warning restore CA1846 +#endif } noEscape = false; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs index d5a32cb40a3..5242910d2db 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs @@ -2738,9 +2738,11 @@ private string ResolveAttributeNamespaceURI(string prefix, string name, string p // if the prefix was "" then // 1) normal properties resolve to the parent Tag namespace. // 2) Attached properties resolve to the "" default namespace. -#pragma warning disable CA1847 +#if NET + if (!name.Contains('.')) +#else if (!name.Contains(".")) -#pragma warning restore CA1847 +#endif attribNamespaceURI = parentURI; else attribNamespaceURI = XmlReader.LookupNamespace(""); From 49249b52133199129d3f88f3d75fd0eab1575a0d Mon Sep 17 00:00:00 2001 From: Himanshi Goyal Date: Mon, 3 Feb 2025 12:16:10 +0530 Subject: [PATCH 6/7] using StringBuilderbuilder.Append(String,int,int) --- .../System/Windows/Markup/MarkupExtensionParser.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs index 24e3c0e6f22..05ff5b6675d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs @@ -1628,11 +1628,7 @@ internal static void RemoveEscapes(ref string value) if (builder == null) { builder = new StringBuilder(value.Length); -#if NET - builder.Append(value.AsSpan(0,i)); -#else - builder.Append(value.Substring(0,i)); -#endif + builder.Append(value, 0, i); } noEscape = false; } From 03e69581c313c7d2cf90c74b8b4fea881c63f0b8 Mon Sep 17 00:00:00 2001 From: Himanshi Goyal Date: Mon, 3 Feb 2025 16:50:07 +0530 Subject: [PATCH 7/7] Changing NET check to NETFX check --- .../src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs | 2 +- .../Microsoft/Build/Tasks/Windows/UidManager.cs | 2 +- .../System/Windows/Markup/MarkupExtensionParser.cs | 2 +- .../System/Windows/Markup/XamlReaderHelper.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs index 7b58153636d..a808c577ebf 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskHelper.cs @@ -203,7 +203,7 @@ internal static string GetWholeExceptionMessage(Exception exception) while (e.InnerException != null) { Exception eInner = e.InnerException; -#if NET +#if !NETFX if (!e.Message.Contains(eInner.Message, StringComparison.Ordinal)) #else if (e.Message.IndexOf(eInner.Message, StringComparison.Ordinal) == -1) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs index 4d4384ad6e5..404a4a49def 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs @@ -518,7 +518,7 @@ private UidCollector ParseFile(string fileName) collector.RootElementLinePosition = reader.LinePosition; } -#if NET +#if !NETFX if (reader.Name.Contains('.')) #else if (reader.Name.Contains(".")) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs index 05ff5b6675d..43880ba0ae4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/MarkupExtensionParser.cs @@ -1465,7 +1465,7 @@ private string ResolveAttributeNamespaceURI(string prefix, string name, string p // if the prefix was "" then // 1) normal properties resolve to the parent Tag namespace. // 2) Attached properties resolve to the "" default namespace. -#if NET +#if !NETFX if (!name.Contains('.')) #else if (!name.Contains(".")) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs index 5242910d2db..273c839b755 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs @@ -2738,7 +2738,7 @@ private string ResolveAttributeNamespaceURI(string prefix, string name, string p // if the prefix was "" then // 1) normal properties resolve to the parent Tag namespace. // 2) Attached properties resolve to the "" default namespace. -#if NET +#if !NETFX if (!name.Contains('.')) #else if (!name.Contains("."))