From 9dc2187df07faca928f2a84fbbe2c7ffe893faa5 Mon Sep 17 00:00:00 2001 From: h3xds1nz Date: Fri, 7 Mar 2025 12:17:12 +0100 Subject: [PATCH] Avoid specialized-generic methods for object null checks --- .../Input/Stylus/Common/StylusTraceLogger.cs | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusTraceLogger.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusTraceLogger.cs index aae0512b972..28da9fe31cb 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusTraceLogger.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusTraceLogger.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // @@ -105,8 +105,8 @@ public StylusDeviceInfo(int id, string name, string pnpId, TabletHardwareCapabil Name = name; PlugAndPlayId = pnpId; Capabilities = capabilities.ToString("F"); - TabletSize = new StylusTraceLogger.StylusSize(tabletSize); - ScreenSize = new StylusTraceLogger.StylusSize(screenSize); + TabletSize = new StylusSize(tabletSize); + ScreenSize = new StylusSize(screenSize); DeviceType = deviceType.ToString("F"); MaxContacts = maxContacts; } @@ -202,7 +202,7 @@ internal static void LogStartup() /// The statistics to log internal static void LogStatistics(StylusStatistics stylusData) { - Requires(stylusData != null); + ArgumentNullException.ThrowIfNull(stylusData); Log(StatisticsTag, stylusData); } @@ -221,7 +221,7 @@ internal static void LogReentrancyRetryLimitReached() /// internal static void LogError(string error) { - Requires(error != null); + ArgumentNullException.ThrowIfNull(error); Log(ErrorTag, new StylusErrorEventData() { Error = error }); } @@ -232,7 +232,7 @@ internal static void LogError(string error) /// internal static void LogDeviceConnect(StylusDeviceInfo deviceInfo) { - Requires(deviceInfo != null); + ArgumentNullException.ThrowIfNull(deviceInfo); Log(DeviceConnectTag, deviceInfo); } @@ -268,19 +268,6 @@ internal static void LogShutdown() #region Utility - /// - /// Throws exception when condition is not met. We can't use the contracts version of this - /// since ccrewrite does not work on C++\CLI or netmodules and PresentationCore is a hybrid - /// assembly. - /// - /// The type of exception to throw - /// The condition to check - private static void Requires(bool condition) - where T : Exception, new() - { - if (!condition) throw new T(); - } - /// /// Logs a tag with no associated data ///