From aea6787fc708558de1c3391d1ff3ab0229a65e87 Mon Sep 17 00:00:00 2001 From: Andrew Sarratori Date: Fri, 4 Apr 2025 15:15:32 -0400 Subject: [PATCH 1/4] Make changes to some WPF code that is functionality equivalent to existing calls --- .gitignore | 2 ++ .../internal/DpiUtil/DpiUtil+HwndDpiInfo.cs | 2 ++ .../DpiUtil+ProcessDpiAwarenessHelper.cs | 1 + .../DpiUtil/DpiUtil+WindowDpiScaleHelper.cs | 1 + .../MS/internal/FontCache/FamilyCollection.cs | 2 +- .../IO/Packaging/DeobfuscatingStream.cs | 2 +- .../TextFormatting/NumberSubstitution.cs | 2 +- .../PresentationCore/PresentationCore.csproj | 1 - .../Input/InputProcessorProfilesLoader.cs | 2 ++ .../Windows/Input/InputScopeConverter.cs | 2 +- .../Windows/Input/Stylus/Wisp/WispLogic.cs | 1 + .../Windows/Input/TextCompositionManager.cs | 1 + .../System/Windows/InterOp/HwndSource.cs | 1 + .../Windows/Media/Imaging/PropVariant.cs | 2 +- .../Media/MediaContextNotificationWindow.cs | 1 + .../System/Windows/dataobject.cs | 1 + .../MS/Internal/AppModel/ShellProvider.cs | 1 + .../Internal/PtsHost/ListMarkerSourceInfo.cs | 4 ++-- .../WindowsRuntime/Generated/WinRT.cs | 8 +++---- .../Microsoft/Win32/CommonDialog.cs | 24 ++++++++++--------- .../Microsoft/Win32/CommonItemDialog.cs | 18 +++++++------- .../PresentationFramework.csproj | 1 - .../Controls/ItemContainerGenerator.cs | 4 ++-- .../System/Windows/Data/Binding.cs | 2 +- .../System/Windows/Documents/CaretElement.cs | 1 + .../System/Windows/Documents/FixedSchema.cs | 2 +- .../Windows/Documents/NLGSpellerInterop.cs | 2 ++ .../Windows/Documents/RtfToXamlReader.cs | 4 ++-- .../Documents/TextEditorContextMenu.cs | 2 ++ .../Windows/Documents/TextEditorDragDrop.cs | 5 ++-- .../Windows/Documents/TextEditorTyping.cs | 2 ++ .../ExtensionSimplifierMarkupObject.cs | 6 ++--- .../System/Windows/PropertyPath.cs | 2 +- .../Windows/Shell/WindowChromeWorker.cs | 1 + .../DocumentApplicationDocumentViewer.cs | 2 +- .../src/PresentationUI/PresentationUI.csproj | 2 -- .../src/Shared/MS/Internal/SecurityHelper.cs | 4 +++- .../MS/Win32/NativeMethodsSetLastError.cs | 2 ++ .../src/System.Xaml/System.Xaml.csproj | 1 - .../Xaml/InfosetObjects/XamlObjectWriter.cs | 6 ++--- .../System/Xaml/Parser/MeScanner.cs | 6 +++-- .../WindowsBase/MS/Internal/ContentType.cs | 4 ++-- .../MS/Internal/IO/Packaging/PackUriHelper.cs | 2 +- .../IO/Packaging/PackageDigitalSignature.cs | 2 +- .../src/WindowsBase/WindowsBase.csproj | 1 - 45 files changed, 85 insertions(+), 60 deletions(-) diff --git a/.gitignore b/.gitignore index 732ceba80ea..397921deb69 100644 --- a/.gitignore +++ b/.gitignore @@ -322,6 +322,8 @@ ASALocalRun/ # MSBuild Binary and Structured Log *.binlog +*.err +*.wrn # NVidia Nsight GPU debugger configuration file *.nvuser diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/DpiUtil/DpiUtil+HwndDpiInfo.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/DpiUtil/DpiUtil+HwndDpiInfo.cs index feacd9ba610..90e08756400 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/DpiUtil/DpiUtil+HwndDpiInfo.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/DpiUtil/DpiUtil+HwndDpiInfo.cs @@ -12,6 +12,8 @@ namespace MS.Internal using System.Runtime.InteropServices; using System.Security; + using NativeMethods = MS.Win32.NativeMethods; + internal static partial class DpiUtil { /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/DpiUtil/DpiUtil+ProcessDpiAwarenessHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/DpiUtil/DpiUtil+ProcessDpiAwarenessHelper.cs index 08e1b4143bc..189f76ad0d1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/DpiUtil/DpiUtil+ProcessDpiAwarenessHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/DpiUtil/DpiUtil+ProcessDpiAwarenessHelper.cs @@ -13,6 +13,7 @@ namespace MS.Internal using System.Security; using PROCESS_DPI_AWARENESS = MS.Win32.NativeMethods.PROCESS_DPI_AWARENESS; + using NativeMethods = MS.Win32.NativeMethods; /// /// Contains definition of diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/DpiUtil/DpiUtil+WindowDpiScaleHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/DpiUtil/DpiUtil+WindowDpiScaleHelper.cs index 8aba5bf9fb4..f9bfa9c7f5e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/DpiUtil/DpiUtil+WindowDpiScaleHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/DpiUtil/DpiUtil+WindowDpiScaleHelper.cs @@ -11,6 +11,7 @@ namespace MS.Internal using System.Security; using MONITOR_DPI_TYPE = MS.Win32.NativeMethods.MONITOR_DPI_TYPE; + using NativeMethods = MS.Win32.NativeMethods; /// /// Contains definition of diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FamilyCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FamilyCollection.cs index 18f7172b018..830acc1a4be 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FamilyCollection.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FamilyCollection.cs @@ -474,7 +474,7 @@ private static Text.TextInterface.Font GetFontFromFamily(Text.TextInterface.Font // and at every locale name this font face has. foreach (KeyValuePair name in font.FaceNames) { - if (faceName.Equals(name.Value, StringComparison.OrdinalIgnoreCase)) + if (faceName.Equals(name.Value.AsSpan(), StringComparison.OrdinalIgnoreCase)) { return font; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/DeobfuscatingStream.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/DeobfuscatingStream.cs index 5bc0653b3a8..2d4a7057e63 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/DeobfuscatingStream.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/DeobfuscatingStream.cs @@ -326,7 +326,7 @@ private static byte[] GetGuidByteArray(string guidString) { // Make sure we have at least on '-' since Guid constructor will take both dash'ed and non-dash'ed format of GUID string // while XPS spec requires dash'ed format of GUID - if (!guidString.Contains('-')) + if (!guidString.Contains("-")) { throw new ArgumentException(SR.InvalidPartName); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/NumberSubstitution.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/NumberSubstitution.cs index 7f974fdff3e..0817bcc09ee 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/NumberSubstitution.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/NumberSubstitution.cs @@ -508,7 +508,7 @@ private CultureInfo CreateTraditionalCulture(CultureInfo numberCulture, int firs int n = firstDigit + i - 0x10000; twoChars[0] = (char)((n >> 10) | 0xD800); // high surrogate twoChars[1] = (char)((n & 0x03FF) | 0xDC00); // low surrogate - digits[i] = new string(twoChars); + digits[i] = twoChars.ToString(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj index 113551ddcc2..2664fc6fcbb 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj @@ -12,7 +12,6 @@ - false diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputProcessorProfilesLoader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputProcessorProfilesLoader.cs index bab99c80ed0..0e7e2a2ca12 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputProcessorProfilesLoader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputProcessorProfilesLoader.cs @@ -22,6 +22,8 @@ using System.Diagnostics; using MS.Win32; +using UnsafeNativeMethods = MS.Win32.UnsafeNativeMethods; + namespace System.Windows.Input { //------------------------------------------------------ diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputScopeConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputScopeConverter.cs index e00c119ac3b..f5bf15c24c4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputScopeConverter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputScopeConverter.cs @@ -109,7 +109,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c if (null != stringSource) { - ReadOnlySpan spanSource = stringSource; + ReadOnlySpan spanSource = stringSource.AsSpan(); spanSource = spanSource.Trim(); int periodPos = spanSource.LastIndexOf('.'); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs index 8c5018d258f..f26b03e361c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs @@ -21,6 +21,7 @@ using System.Windows.Media; using System.Windows.Threading; using SR = MS.Internal.PresentationCore.SR; +using UnsafeNativeMethods = MS.Win32.UnsafeNativeMethods; namespace System.Windows.Input.StylusWisp { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/TextCompositionManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/TextCompositionManager.cs index 994009d2d03..c7cb4e7aa89 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/TextCompositionManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/TextCompositionManager.cs @@ -23,6 +23,7 @@ using MS.Internal.PresentationCore; // SecurityHelper using SR=MS.Internal.PresentationCore.SR; +using UnsafeNativeMethods = MS.Win32.UnsafeNativeMethods; namespace System.Windows.Input { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndSource.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndSource.cs index 9fac6a3809b..5e15d27f9f0 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndSource.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndSource.cs @@ -25,6 +25,7 @@ using System.IO; using SR = MS.Internal.PresentationCore.SR; +using UnsafeNativeMethods = MS.Win32.UnsafeNativeMethods; #pragma warning disable 1634, 1691 // suppressing PreSharp warnings diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/PropVariant.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/PropVariant.cs index 3c5748ba293..b7d234b9cd7 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/PropVariant.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/PropVariant.cs @@ -364,7 +364,7 @@ internal void Init(object value) else if (value is char) { varType = (ushort)VarEnum.VT_LPSTR; - pszVal = Marshal.StringToCoTaskMemAnsi(new String(stackalloc char[] { (char)value })); + pszVal = Marshal.StringToCoTaskMemAnsi((stackalloc char[] { (char)value }).ToString()); } else if (type == typeof(short)) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaContextNotificationWindow.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaContextNotificationWindow.cs index 48ab426d965..f81a75380f6 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaContextNotificationWindow.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaContextNotificationWindow.cs @@ -29,6 +29,7 @@ using SR=MS.Internal.PresentationCore.SR; using DllImport=MS.Internal.PresentationCore.DllImport; +using UnsafeNativeMethods = MS.Win32.UnsafeNativeMethods; namespace System.Windows.Media { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/dataobject.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/dataobject.cs index 7a012c78650..07db4dc60c9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/dataobject.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/dataobject.cs @@ -34,6 +34,7 @@ namespace System.Windows using SR=MS.Internal.PresentationCore.SR; using IComDataObject = System.Runtime.InteropServices.ComTypes.IDataObject; + using NativeMethods = MS.Win32.NativeMethods; // PreSharp uses message numbers that the C# compiler doesn't know about. // Disable the C# complaints, per the PreSharp documentation. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ShellProvider.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ShellProvider.cs index 16ddad1bebf..555d4ed6ce0 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ShellProvider.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ShellProvider.cs @@ -21,6 +21,7 @@ namespace MS.Internal.AppModel using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME; using IPersistFile = System.Runtime.InteropServices.ComTypes.IPersistFile; using IStream = System.Runtime.InteropServices.ComTypes.IStream; + using NativeMethods = MS.Win32.NativeMethods; #region Structs diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ListMarkerSourceInfo.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ListMarkerSourceInfo.cs index d78ea8ffd69..8c2c8f6a9e5 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ListMarkerSourceInfo.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ListMarkerSourceInfo.cs @@ -164,11 +164,11 @@ private static string ConvertNumberToString(int number, bool oneBased, string nu if (number < b) { // Optimize common case of single-digit numbers. - return new string(stackalloc char[2] // digit + suffix + return stackalloc char[2] // digit + suffix { numericSymbols[number], NumberSuffix - }); + }.ToString(); } else { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT.cs index 7d74d32f710..f64f48fa9a1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT.cs @@ -136,14 +136,14 @@ public static DllModule Load(string fileName) // Explicitly look for module in the same directory as this one, and // use altered search path to ensure any dependencies in the same directory are found. _moduleHandle = Platform.LoadLibraryExW(System.IO.Path.Combine(_currentModuleDirectory, fileName), IntPtr.Zero, /* LOAD_WITH_ALTERED_SEARCH_PATH */ 8); -#if !NETSTANDARD2_0 && !NETCOREAPP2_0 +#if NET if (_moduleHandle == IntPtr.Zero) { - try - { + try + { // Allow runtime to find module in RID-specific relative subfolder _moduleHandle = NativeLibrary.Load(fileName, Assembly.GetExecutingAssembly(), null); - } + } catch (Exception) { } } #endif diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/CommonDialog.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/CommonDialog.cs index b458a2139ba..3f806dc79d3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/CommonDialog.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/CommonDialog.cs @@ -28,6 +28,8 @@ namespace Microsoft.Win32 using MS.Internal.PresentationFramework; using MS.Win32; + using NativeMethods = MS.Win32.NativeMethods; + /// /// An abstract base class for displaying common dialogs. /// @@ -80,7 +82,7 @@ public virtual Nullable ShowDialog() // Call GetActiveWindow to retrieve the window handle to the active window // attached to the calling thread's message queue. We'll set the owner of // the common dialog to this handle. - IntPtr hwndOwner = UnsafeNativeMethods.GetActiveWindow(); + IntPtr hwndOwner = MS.Win32.UnsafeNativeMethods.GetActiveWindow(); if (hwndOwner == IntPtr.Zero) { @@ -321,16 +323,16 @@ private void MoveToScreenCenter(HandleRef hWnd) ref y); // Call SetWindowPos to actually move the window. - UnsafeNativeMethods.SetWindowPos(hWnd, // handle to the window to move - NativeMethods.NullHandleRef, // window to precede this one in zorder - (int)Math.Round(x), - (int)Math.Round(y), // new X and Y positions - 0, 0, // new width and height, if applicable - // Flags: - // SWP_NOSIZE: Retains current size - // SWP_NOZORDER: retains current zorder - // SWP_NOACTIVATE: does not activate the window - NativeMethods.SWP_NOSIZE | NativeMethods.SWP_NOZORDER | NativeMethods.SWP_NOACTIVATE); + MS.Win32.UnsafeNativeMethods.SetWindowPos(hWnd, // handle to the window to move + NativeMethods.NullHandleRef, // window to precede this one in zorder + (int)Math.Round(x), + (int)Math.Round(y), // new X and Y positions + 0, 0, // new width and height, if applicable + // Flags: + // SWP_NOSIZE: Retains current size + // SWP_NOZORDER: retains current zorder + // SWP_NOACTIVATE: does not activate the window + NativeMethods.SWP_NOSIZE | NativeMethods.SWP_NOZORDER | NativeMethods.SWP_NOACTIVATE); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/CommonItemDialog.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/CommonItemDialog.cs index 0dbac9544da..503eaf8c56e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/CommonItemDialog.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/CommonItemDialog.cs @@ -353,7 +353,7 @@ internal bool MessageBoxWithFocusRestore(string message, bool ret = false; // Get the window that currently has focus and temporarily cache a handle to it - IntPtr focusHandle = UnsafeNativeMethods.GetFocus(); + IntPtr focusHandle = MS.Win32.UnsafeNativeMethods.GetFocus(); try { @@ -367,7 +367,7 @@ internal bool MessageBoxWithFocusRestore(string message, { // Return focus to the window that had focus before we showed the messagebox. // SetFocus can handle improper hwnd values, including null. - UnsafeNativeMethods.SetFocus(new HandleRef(this, focusHandle)); + MS.Win32.UnsafeNativeMethods.SetFocus(new HandleRef(this, focusHandle)); } return ret; } @@ -577,7 +577,7 @@ private bool HandleItemOk(IFileDialog dialog) // When this callback occurs, the HWND is visible and we need to // grab it because it is used for various things like looking up the // DialogCaption. - UnsafeNativeMethods.IOleWindow oleWindow = (UnsafeNativeMethods.IOleWindow)dialog; + MS.Win32.UnsafeNativeMethods.IOleWindow oleWindow = (MS.Win32.UnsafeNativeMethods.IOleWindow)dialog; oleWindow.GetWindow(out _hwndFileDialog); string[] saveItemNames = _itemNames; @@ -677,20 +677,20 @@ private string DialogCaption { get { - if (!UnsafeNativeMethods.IsWindow(new HandleRef(this, _hwndFileDialog))) + if (!MS.Win32.UnsafeNativeMethods.IsWindow(new HandleRef(this, _hwndFileDialog))) { return String.Empty; } // Determine the length of the text we want to retrieve... - int textLen = UnsafeNativeMethods.GetWindowTextLength(new HandleRef(this, _hwndFileDialog)); + int textLen = MS.Win32.UnsafeNativeMethods.GetWindowTextLength(new HandleRef(this, _hwndFileDialog)); // then make a StringBuilder... StringBuilder sb = new StringBuilder(textLen + 1); // and call GetWindowText to fill it up... - UnsafeNativeMethods.GetWindowText(new HandleRef(this, _hwndFileDialog), - sb /*target string*/, - sb.Capacity /* max # of chars to copy before truncation occurs */ - ); + MS.Win32.UnsafeNativeMethods.GetWindowText(new HandleRef(this, _hwndFileDialog), + sb /*target string*/, + sb.Capacity /* max # of chars to copy before truncation occurs */ + ); // then return the results. return sb.ToString(); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj index 91c17599028..3699d671419 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj @@ -12,7 +12,6 @@ - false diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemContainerGenerator.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemContainerGenerator.cs index 3eb77e5a577..f49e4cd4bff 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemContainerGenerator.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemContainerGenerator.cs @@ -1130,8 +1130,8 @@ void FormatCollectionChangedSource(int level, object source, bool? isLikely, Lis if (index >= 0) { ReadOnlySpan token = aqn.AsSpan(index + PublicKeyToken.Length); - if (token.Equals(MS.Internal.PresentationFramework.BuildInfo.WCP_PUBLIC_KEY_TOKEN, StringComparison.OrdinalIgnoreCase) || - token.Equals(MS.Internal.PresentationFramework.BuildInfo.DEVDIV_PUBLIC_KEY_TOKEN, StringComparison.OrdinalIgnoreCase)) + if (token.Equals(MS.Internal.PresentationFramework.BuildInfo.WCP_PUBLIC_KEY_TOKEN.AsSpan(), StringComparison.OrdinalIgnoreCase) || + token.Equals(MS.Internal.PresentationFramework.BuildInfo.DEVDIV_PUBLIC_KEY_TOKEN.AsSpan(), StringComparison.OrdinalIgnoreCase)) { isLikely = false; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/Binding.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/Binding.cs index f14c5949588..78486860b00 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/Binding.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/Binding.cs @@ -779,7 +779,7 @@ internal bool TreeContextIsRequired treeContextIsRequired = (_attachedPropertiesInPath > 0); // namespace prefixes in the XPath need an XmlNamespaceManager - if (!treeContextIsRequired && HasValue(Feature.XPath) && XPath.Contains(':')) + if (!treeContextIsRequired && HasValue(Feature.XPath) && XPath.Contains(":")) { treeContextIsRequired = true; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CaretElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CaretElement.cs index 64a21fd7fc3..548c39829da 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CaretElement.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CaretElement.cs @@ -20,6 +20,7 @@ namespace System.Windows.Documents using System.Windows.Interop; using System.Windows.Controls.Primitives; + using NativeMethods = MS.Win32.NativeMethods; // Disable pragma warnings to enable PREsharp pragmas #pragma warning disable 1634, 1691 diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs index 747b191941e..d1a2a983183 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs @@ -442,7 +442,7 @@ public override string[] ExtractUriFromAttr(string attrName, string attrValue) attrName.Equals("Stroke", StringComparison.Ordinal)) { ReadOnlySpan attrValueSpan = attrValue.AsSpan().Trim(); - if (attrValueSpan.StartsWith(_contextColor, StringComparison.Ordinal)) + if (attrValueSpan.StartsWith(_contextColor.AsSpan(), StringComparison.Ordinal)) { attrValueSpan = attrValueSpan.Slice(_contextColor.Length).Trim(); int spacePos = attrValueSpan.IndexOf(' '); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/NLGSpellerInterop.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/NLGSpellerInterop.cs index 08579c01e13..129fe9c5abd 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/NLGSpellerInterop.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/NLGSpellerInterop.cs @@ -20,6 +20,8 @@ namespace System.Windows.Documents using System.Windows.Controls; using MS.Internal.PresentationFramework; + using NativeMethods = MS.Win32.NativeMethods; + // Custom COM marshalling code and interfaces for interaction // with the Natural Language Group's nl6 proofing engine. internal class NLGSpellerInterop : SpellerInteropBase diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RtfToXamlReader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RtfToXamlReader.cs index 32a1f5529e7..1694e4bf9f2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RtfToXamlReader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/RtfToXamlReader.cs @@ -275,7 +275,7 @@ internal static bool StringToInt(ReadOnlySpan s, ref int i) internal static string StringToXMLAttribute(string s) { - if (!s.Contains('"')) + if (!s.Contains("\"")) { return s; } @@ -3747,7 +3747,7 @@ internal Hashtable FontMappings if (lhs_name.Length > rhs_name.Length) { ReadOnlySpan s = lhs_name.AsSpan(0, rhs_name.Length); - if (s.Equals(rhs_name, StringComparison.OrdinalIgnoreCase)) + if (s.Equals(rhs_name.AsSpan(), StringComparison.OrdinalIgnoreCase)) { bAdd = true; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorContextMenu.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorContextMenu.cs index 50b134d6fe9..757c2f883cc 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorContextMenu.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorContextMenu.cs @@ -20,6 +20,8 @@ namespace System.Windows.Documents using MS.Win32; using System.Windows.Interop; + using NativeMethods = MS.Win32.NativeMethods; + // A Component of TextEditor supporting the default ContextMenu. internal static class TextEditorContextMenu { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorDragDrop.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorDragDrop.cs index afcc86538c6..5e489d6344e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorDragDrop.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorDragDrop.cs @@ -33,8 +33,9 @@ namespace System.Windows.Documents using MS.Internal.Documents; using MS.Internal.Commands; // CommandHelpers using MS.Internal.PresentationFramework; //Demand for drag and drop - - using SecurityHelper=MS.Internal.SecurityHelper; + + using SecurityHelper = MS.Internal.SecurityHelper; + using NativeMethods = MS.Win32.NativeMethods; /// /// Text editing service for controls. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorTyping.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorTyping.cs index 5084564a256..ffc350984a0 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorTyping.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorTyping.cs @@ -30,6 +30,8 @@ namespace System.Windows.Documents using MS.Internal.Documents; using MS.Internal.Commands; // CommandHelpers + using NativeMethods = MS.Win32.NativeMethods; + /// /// Subcomponent of TextEditor class - Support for Typing /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/ExtensionSimplifierMarkupObject.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/ExtensionSimplifierMarkupObject.cs index 657b8e473cc..b5f3b1510f8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/ExtensionSimplifierMarkupObject.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/ExtensionSimplifierMarkupObject.cs @@ -354,9 +354,9 @@ private string ConvertMarkupItemToString(MarkupObject item) { Debug.Assert(!propertyWritten, "An argument was returned after a property was set. All arguments must be returned first and in order"); } - - ReadOnlySpan value = property.StringValue; - + + ReadOnlySpan value = property.StringValue.AsSpan(); + if (!value.IsEmpty) { if (value[0] == '{') diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPath.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPath.cs index 7608933a4ec..63abb3fc13d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPath.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPath.cs @@ -281,7 +281,7 @@ internal int ComputeUnresolvedAttachedPropertiesInPath() { // a dot inside parens, when there's no early-bound accessor, // is an unresolved PD name - if (name.Contains('.')) + if (name.Contains(".")) ++ result; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/WindowChromeWorker.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/WindowChromeWorker.cs index ea33f6880cf..156b4346548 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/WindowChromeWorker.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/WindowChromeWorker.cs @@ -23,6 +23,7 @@ namespace Microsoft.Windows.Shell using Standard; using HANDLE_MESSAGE = System.Collections.Generic.KeyValuePair; + using NativeMethods = Standard.NativeMethods; internal class WindowChromeWorker : DependencyObject { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/DocumentApplicationDocumentViewer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/DocumentApplicationDocumentViewer.cs index 22cf9f83226..0a500c252ef 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/DocumentApplicationDocumentViewer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/DocumentApplicationDocumentViewer.cs @@ -1749,7 +1749,7 @@ private void OnZoomComboBoxValueEdited(object sender, EventArgs e) { double result; // Parse the new value. - if (StringToZoomValue(ZoomComboBox.Text, out result)) + if (StringToZoomValue(ZoomComboBox.Text.AsSpan(), out result)) { // The value is valid, set on DocumentViewer Zoom = result; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationUI/PresentationUI.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationUI/PresentationUI.csproj index 918fce88dc4..62f13c51127 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationUI/PresentationUI.csproj +++ b/src/Microsoft.DotNet.Wpf/src/PresentationUI/PresentationUI.csproj @@ -1,8 +1,6 @@  - - AnyCPU;x64;arm64 false diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SecurityHelper.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SecurityHelper.cs index 36f0433d7f3..4556060ff7f 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SecurityHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SecurityHelper.cs @@ -45,6 +45,8 @@ namespace MS.Internal.Drt #if PRESENTATION_CORE using MS.Internal.AppModel; +using NativeMethods = MS.Win32.NativeMethods; +using UnsafeNativeMethods = MS.Win32.UnsafeNativeMethods; #endif #if PRESENTATIONFRAMEWORK_ONLY @@ -67,7 +69,7 @@ namespace MS.Internal.Drt #endif -internal static class SecurityHelper + internal static class SecurityHelper { #if PRESENTATION_CORE diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/NativeMethodsSetLastError.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/NativeMethodsSetLastError.cs index 8ec506b45fe..ca8bce4b014 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/NativeMethodsSetLastError.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/NativeMethodsSetLastError.cs @@ -31,6 +31,8 @@ namespace MS.Internal.Drt using System.Windows; using MS.Win32; + using NativeMethods = MS.Win32.NativeMethods; + internal static class NativeMethodsSetLastError { private const string PresentationNativeDll = "PresentationNative_cor3.dll"; diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System.Xaml.csproj b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System.Xaml.csproj index b515a7646e1..5518a80a7e2 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System.Xaml.csproj +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System.Xaml.csproj @@ -2,7 +2,6 @@ {9AC36357-34B7-40A1-95CA-FE9F46D089A7} System.Xaml - AnyCPU;x64;arm64 $(NoWarn);0618;NU5125;0618 $(DefineConstants);OLDRESOURCES;SYSTEM_XAML diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlObjectWriter.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlObjectWriter.cs index 6adbbfa2a8c..197af0d012b 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlObjectWriter.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlObjectWriter.cs @@ -1967,7 +1967,7 @@ private void Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx) if (value is NameFixupToken && parentProperty != XamlLanguage.Items) { NameFixupToken token = value as NameFixupToken; - string names = String.Join(',', token.NeededNames.ToArray()); + string names = String.Join(",", token.NeededNames.ToArray()); string msg = SR.Format(SR.ForwardRefDirectives, names); throw ctx.WithLineInfo(new XamlObjectWriterException(msg)); } @@ -2004,7 +2004,7 @@ private void Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx) // Only the key directive may be assigned a reference. if (parentProperty != XamlLanguage.Key) { - string names = String.Join(',', token.NeededNames.ToArray()); + string names = String.Join(",", token.NeededNames.ToArray()); string msg = SR.Format(SR.ForwardRefDirectives, names); throw ctx.WithLineInfo(new XamlObjectWriterException(msg)); } @@ -2057,7 +2057,7 @@ private void Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx) if (parentProperty != XamlLanguage.Key) { NameFixupToken token = (NameFixupToken)value; - string names = String.Join(',', token.NeededNames.ToArray()); + string names = String.Join(",", token.NeededNames.ToArray()); string msg = SR.Format(SR.ForwardRefDirectives, names); throw ctx.WithLineInfo(new XamlObjectWriterException(msg)); } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/MeScanner.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/MeScanner.cs index 254e6089ddb..8e07e90b98c 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/MeScanner.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/MeScanner.cs @@ -48,6 +48,8 @@ internal class MeScanner public const char Backslash = '\\'; public const char NullChar = '\0'; + public const string BackslashString = "\\"; + enum StringState { Value, Type, Property }; XamlParserContext _context; @@ -242,8 +244,8 @@ private static string RemoveEscapes(string value) { value = value.Substring(2); } - - if (!value.Contains(Backslash)) + + if (!value.Contains(BackslashString)) { return value; } diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs index 8cb6268a18c..7ae2b2a4262 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs @@ -105,13 +105,13 @@ internal ContentType(string contentType) if (semiColonIndex == -1) { // Parse content type similar to - type/subtype - ParseTypeAndSubType(contentType); + ParseTypeAndSubType(contentType.AsSpan()); } else { // Parse content type similar to - type/subtype ; param1=value1 ; param2=value2 ; param3="value3" ParseTypeAndSubType(contentType.AsSpan(0, semiColonIndex)); - ParseParameterAndValue(contentType.Substring(semiColonIndex)); + ParseParameterAndValue(contentType.Substring(semiColonIndex).AsSpan()); } } 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 df6057ccba5..299c5a5731e 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 @@ -213,7 +213,7 @@ private static ArgumentException GetExceptionIfAbsoluteUri(Uri uri) private static ArgumentException GetExceptionIfFragmentPresent(string partName) { - if (partName.Contains('#')) + if (partName.Contains("#")) return new ArgumentException(SR.PartUriCannotHaveAFragment); else return null; diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignature.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignature.cs index 387ae2bfc93..2995baa8414 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignature.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignature.cs @@ -211,7 +211,7 @@ public String SignatureType /// Future signature types will return objects of different classes. /// /// Thrown if associated digital signature has been deleted. - public Signature Signature + public System.Security.Cryptography.Xml.Signature Signature { get { diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/WindowsBase.csproj b/src/Microsoft.DotNet.Wpf/src/WindowsBase/WindowsBase.csproj index e6155312cbd..6ec5301c16c 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/WindowsBase.csproj +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/WindowsBase.csproj @@ -7,7 +7,6 @@ $(NoWarn);0618 false {FA69991B-9696-42D0-A5C7-F5E73F0DEE9E} - AnyCPU;x64;arm64 From eebb2a8f33da2b0abd49501cf4722c0dff60a0e2 Mon Sep 17 00:00:00 2001 From: Andrew Sarratori Date: Mon, 7 Apr 2025 10:26:46 -0400 Subject: [PATCH 2/4] A couple more equivalent changes --- .../MS/internal/DpiUtil/DpiUtil+SystemDpiHelper.cs | 1 + .../MS/internal/IO/Packaging/ByteRangeDownloader.cs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/DpiUtil/DpiUtil+SystemDpiHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/DpiUtil/DpiUtil+SystemDpiHelper.cs index 6b8a90dee93..1780c0d8c58 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/DpiUtil/DpiUtil+SystemDpiHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/DpiUtil/DpiUtil+SystemDpiHelper.cs @@ -13,6 +13,7 @@ namespace MS.Internal using System.Security; using PROCESS_DPI_AWARENESS = MS.Win32.NativeMethods.PROCESS_DPI_AWARENESS; + using NativeMethods = MS.Win32.NativeMethods; /// /// Contains definition of diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs index 9cb8d37ac94..0a215e43329 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs @@ -816,7 +816,7 @@ static private bool CheckContentRange(WebHeaderCollection responseHeaders, int b // Get the instance length // ContentRange: ZZZ contentRangeSpan = contentRangeSpan.Slice(index + 1); - if (!contentRangeSpan.Equals("*", StringComparison.Ordinal)) + if (!contentRangeSpan.Equals(Asterisk.AsSpan(), StringComparison.Ordinal)) { // Note: for firstByteOffset and lastByteOffset, we are using Int32.Parse to make sure Int32.Parse to throw // if it is not an integer or the integer is bigger than Int32 since HttpWebRequest.AddRange @@ -891,6 +891,7 @@ static private bool CheckContentRange(WebHeaderCollection responseHeaders, int b private const String ByteRangeUnit = "BYTES "; private const String ContentRangeHeader = "Content-Range"; + private const String Asterisk = "*"; #endregion Private Fields } From ef7f071dbde78346e32524d574df7e9fb2f569da Mon Sep 17 00:00:00 2001 From: Andrew Sarratori Date: Mon, 7 Apr 2025 14:45:21 -0400 Subject: [PATCH 3/4] Another round of equivalent changes --- .../WindowsRuntime/Generated/WinRT/ExceptionHelpers.cs | 4 ++-- .../System/Windows/Documents/XamlToRtfWriter.cs | 8 ++++---- .../System/Windows/Markup/Baml2006/Baml2006Reader.cs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT/ExceptionHelpers.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT/ExceptionHelpers.cs index 5152bc7a30e..fc74c0abf70 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT/ExceptionHelpers.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Generated/WinRT/ExceptionHelpers.cs @@ -168,7 +168,7 @@ public static unsafe void SetErrorInfo(Exception ex) { // If the exception has information for an IRestrictedErrorInfo, use that // as our error so as to propagate the error through WinRT end-to-end. - if (ex.TryGetRestrictedLanguageErrorObject(out var restrictedErrorObject)) + if (ex.TryGetRestrictedLanguageErrorObject(out IObjectReference restrictedErrorObject)) { using (restrictedErrorObject) { @@ -215,7 +215,7 @@ public static void ReportUnhandledError(Exception ex) public static int GetHRForException(Exception ex) { int hr = ex.HResult; - if (ex.TryGetRestrictedLanguageErrorObject(out var restrictedErrorObject)) + if (ex.TryGetRestrictedLanguageErrorObject(out IObjectReference restrictedErrorObject)) { restrictedErrorObject.AsType().GetErrorDetails(out _, out hr, out _, out _); } 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 7d1bbaaa036..8a5cf6f3d03 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 @@ -2888,7 +2888,7 @@ private XamlToRtfError HandleAttributes(ConverterState converterState, IXamlAttr case XamlAttribute.XAFontSize: double fs = 0f; - if (XamlParserHelper.ConvertToFontSize(converterState, valueString, ref fs)) + if (XamlParserHelper.ConvertToFontSize(converterState.AsSpan(), valueString, ref fs)) { formatState.FontSize = (long)Math.Round(fs); } @@ -3181,7 +3181,7 @@ private XamlToRtfError HandleAttributes(ConverterState converterState, IXamlAttr case XamlAttribute.XAMargin: { XamlThickness thickness = new XamlThickness(0f, 0f, 0f, 0f); - if (XamlParserHelper.ConvertToThickness(converterState, valueString, ref thickness)) + if (XamlParserHelper.ConvertToThickness(converterState, valueString.AsSpan(), ref thickness)) { formatState.LI = Converters.PxToTwipRounded(thickness.Left); formatState.RI = Converters.PxToTwipRounded(thickness.Right); @@ -3194,7 +3194,7 @@ private XamlToRtfError HandleAttributes(ConverterState converterState, IXamlAttr case XamlAttribute.XAPadding: { XamlThickness t = new XamlThickness(0f, 0f, 0f, 0f); - if (XamlParserHelper.ConvertToThickness(converterState, valueString, ref t)) + if (XamlParserHelper.ConvertToThickness(converterState, valueString.AsSpan(), ref t)) { if (xamlTag == XamlTag.XTParagraph) { @@ -3217,7 +3217,7 @@ private XamlToRtfError HandleAttributes(ConverterState converterState, IXamlAttr case XamlAttribute.XABorderThickness: { XamlThickness t = new XamlThickness(0f, 0f, 0f, 0f); - if (XamlParserHelper.ConvertToThickness(converterState, valueString, ref t)) + if (XamlParserHelper.ConvertToThickness(converterState, valueString.AsSpan(), ref t)) { if (xamlTag == XamlTag.XTParagraph) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006Reader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006Reader.cs index f6344500af4..dd454a95a12 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006Reader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006Reader.cs @@ -2084,7 +2084,7 @@ private string Logic_GetFullXmlns(string uriInput) if (colonIdx != -1) { ReadOnlySpan uriTypePrefix = uriInput.AsSpan(0, colonIdx); - if (uriTypePrefix.Equals("clr-namespace", StringComparison.Ordinal)) + if (uriTypePrefix.Equals("clr-namespace".AsSpan(), StringComparison.Ordinal)) { //We have a clr-namespace so do special processing int semicolonIdx = uriInput.IndexOf(';'); @@ -2105,7 +2105,7 @@ private string Logic_GetFullXmlns(string uriInput) throw new ArgumentException(SR.Format(SR.MissingTagInNamespace, "=", uriInput)); } ReadOnlySpan keyword = uriInput.AsSpan(assemblyKeywordStartIdx, equalIdx - assemblyKeywordStartIdx); - if (!keyword.Equals("assembly", StringComparison.Ordinal)) + if (!keyword.Equals("assembly".AsSpan(), StringComparison.Ordinal)) { throw new ArgumentException(SR.Format(SR.AssemblyTagMissing, "assembly", uriInput)); } From cddac7c4beb3502bb91f71b0fc4f180c2d8a8de0 Mon Sep 17 00:00:00 2001 From: Andrew Sarratori Date: Mon, 7 Apr 2025 15:02:16 -0400 Subject: [PATCH 4/4] Missed a bunch of AsSpan calls --- .../Windows/Documents/XamlToRtfWriter.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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 8a5cf6f3d03..df9e2f4890f 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 @@ -2888,7 +2888,7 @@ private XamlToRtfError HandleAttributes(ConverterState converterState, IXamlAttr case XamlAttribute.XAFontSize: double fs = 0f; - if (XamlParserHelper.ConvertToFontSize(converterState.AsSpan(), valueString, ref fs)) + if (XamlParserHelper.ConvertToFontSize(converterState, valueString.AsSpan(), ref fs)) { formatState.FontSize = (long)Math.Round(fs); } @@ -3017,7 +3017,7 @@ private XamlToRtfError HandleAttributes(ConverterState converterState, IXamlAttr { int nRowSpan = 0; - if (Converters.StringToInt(valueString, ref nRowSpan)) + if (Converters.StringToInt(valueString.AsSpan(), ref nRowSpan)) { if (documentNode.Type == DocumentNodeType.dnCell) { @@ -3031,7 +3031,7 @@ private XamlToRtfError HandleAttributes(ConverterState converterState, IXamlAttr { int nColSpan = 0; - if (Converters.StringToInt(valueString, ref nColSpan)) + if (Converters.StringToInt(valueString.AsSpan(), ref nColSpan)) { if (documentNode.Type == DocumentNodeType.dnCell) { @@ -3045,7 +3045,7 @@ private XamlToRtfError HandleAttributes(ConverterState converterState, IXamlAttr { double d = 0f; - if (Converters.StringToDouble(valueString, ref d)) + if (Converters.StringToDouble(valueString.AsSpan(), ref d)) { if (documentNode.Type == DocumentNodeType.dnTable) { @@ -3070,7 +3070,7 @@ private XamlToRtfError HandleAttributes(ConverterState converterState, IXamlAttr { double d = 0f; - if (Converters.StringToDouble(valueString, ref d)) + if (Converters.StringToDouble(valueString.AsSpan(), ref d)) { int nTableAt = dna.FindPending(DocumentNodeType.dnTable); if (nTableAt >= 0) @@ -3087,7 +3087,7 @@ private XamlToRtfError HandleAttributes(ConverterState converterState, IXamlAttr else if (xamlTag == XamlTag.XTImage) { double d = 0f; - Converters.StringToDouble(valueString, ref d); + Converters.StringToDouble(valueString.AsSpan(), ref d); documentNode.FormatState.ImageWidth = d; } break; @@ -3096,7 +3096,7 @@ private XamlToRtfError HandleAttributes(ConverterState converterState, IXamlAttr if (xamlTag == XamlTag.XTImage) { double d = 0f; - Converters.StringToDouble(valueString, ref d); + Converters.StringToDouble(valueString.AsSpan(), ref d); documentNode.FormatState.ImageHeight = d; } break; @@ -3105,7 +3105,7 @@ private XamlToRtfError HandleAttributes(ConverterState converterState, IXamlAttr if (xamlTag == XamlTag.XTImage) { double d = 0f; - Converters.StringToDouble(valueString, ref d); + Converters.StringToDouble(valueString.AsSpan(), ref d); documentNode.FormatState.ImageBaselineOffset = d; documentNode.FormatState.IncludeImageBaselineOffset = true; } @@ -3585,12 +3585,12 @@ internal static bool ConvertToFontSize(ConverterState converterState, ReadOnlySp internal static bool ConvertToTextIndent(ConverterState converterState, string s, ref double d) { - return Converters.StringToDouble(s, ref d); + return Converters.StringToDouble(s.AsSpan(), ref d); } internal static bool ConvertToLineHeight(ConverterState converterState, string s, ref double d) { - return Converters.StringToDouble(s, ref d); + return Converters.StringToDouble(s.AsSpan(), ref d); } internal static bool ConvertToColor(ConverterState converterState, string brush, ref long colorIndex)