From 906b612dbc7afc293ac0827f6e904373c044f25f Mon Sep 17 00:00:00 2001 From: Thad House Date: Sun, 17 Nov 2024 16:26:04 -0800 Subject: [PATCH] .NET 9 compilation --- .editorconfig | 3 ++ .../LogGenerator/LogGeneratorTest.cs | 1 - .../LogGenerator/LogGeneratorTestVb.cs | 1 - codehelp/CodeHelpers/IndentedStringBuilder.cs | 1 - .../LogGenerator/LogAttributeInfo.cs | 1 - .../CodeHelpers/LogGenerator/LoggableType.cs | 1 - .../SourceGenerator/LogGeneratorVb.cs | 1 - .../ParameterlessStructDiagnostics.cs | 2 - codehelp/CodeHelpers/SymbolExtensions.cs | 1 - codehelp/CodeHelpers/TypeDeclarationModel.cs | 1 - dev/desktopDev/Program.cs | 5 --- src/hal/CANStreamMessage.cs | 8 ++++ src/hal/JoystickAxis.cs | 8 ++++ src/hal/JoystickDescriptor.cs | 6 +++ src/hal/JoystickPOVs.cs | 4 ++ .../Simulation/HalAccelerometerData.cs | 1 - .../Simulation/HalAddressableLEDData.cs | 1 - .../Natives/Simulation/HalAnalogGyroData.cs | 1 - src/hal/Natives/Simulation/HalAnalogInData.cs | 1 - .../Natives/Simulation/HalAnalogOutData.cs | 1 - .../Simulation/HalAnalogTriggerData.cs | 1 - src/hal/Natives/Simulation/HalCTREPCMData.cs | 1 - src/hal/Natives/Simulation/HalDIOData.cs | 1 - .../Natives/Simulation/HalDigitalPWMData.cs | 1 - .../Natives/Simulation/HalDutyCycleData.cs | 1 - src/hal/Natives/Simulation/HalEncoderData.cs | 1 - src/hal/Natives/Simulation/HalNotifierData.cs | 2 - src/hal/Natives/Simulation/HalPWMData.cs | 1 - .../Simulation/HalPowerDistributionData.cs | 1 - src/hal/Natives/Simulation/HalREVPHData.cs | 1 - src/hal/Natives/Simulation/HalRelayData.cs | 1 - .../Simulation/HalSPIAccelerometerData.cs | 1 - src/hal/Natives/Simulation/NotifyListener.cs | 5 --- src/hal/Natives/Simulation/Reset.cs | 2 - src/newcommands/Command.cs | 2 - src/newcommands/ConditionalCommand.cs | 2 + src/newcommands/DeferredCommand.cs | 2 + src/ntcore/ConnectionInfo.cs | 3 +- src/ntcore/NetworkTable.cs | 1 - src/ntcore/TopicInfo.cs | 3 +- src/stereologue/Attributes.cs | 2 - src/stereologue/LogType.cs | 2 - src/stereologue/Stereologuer.cs | 3 +- src/wpilibsharp/DataLogManager.cs | 4 ++ src/wpilibsharp/DriverStation.cs | 40 ++++++++++--------- src/wpilibsharp/IterativeRobotBase.cs | 1 - src/wpilibsharp/Notifier.cs | 2 +- src/wpilibsharp/RobotBase.cs | 4 +- src/wpilibsharp/RobotController.cs | 1 - .../Simulation/AddressableLEDSim.cs | 3 +- src/wpilibsharp/Simulation/CallbackStore.cs | 1 - src/wpilibsharp/Watchdog.cs | 1 - src/wpimath/MathSharedStore.cs | 5 +-- src/wpiutil/Concurrent/Event.cs | 1 - src/wpiutil/Concurrent/Synchronization.cs | 1 - src/wpiutil/Logging/DataLog.cs | 5 ++- src/wpiutil/Natives/SynchronizationNative.cs | 5 +-- .../Serialization/Struct/Parsing/Parser.cs | 2 +- 58 files changed, 75 insertions(+), 90 deletions(-) diff --git a/.editorconfig b/.editorconfig index 575e3203..6cabde80 100644 --- a/.editorconfig +++ b/.editorconfig @@ -51,6 +51,7 @@ dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion dotnet_style_prefer_auto_properties = true:silent dotnet_style_prefer_conditional_expression_over_assignment = true:silent dotnet_style_prefer_conditional_expression_over_return = true:silent +dotnet_style_namespace_match_folder = true:silent ############################### # Naming Conventions # ############################### @@ -92,6 +93,8 @@ csharp_style_deconstructed_variable_declaration = true:suggestion csharp_prefer_simple_default_expression = true:suggestion csharp_style_pattern_local_over_anonymous_function = true:suggestion csharp_style_inlined_variable_declaration = true:suggestion +csharp_style_namespace_declarations = file_scoped +csharp_style_prefer_primary_constructors= false:silent ############################### # C# Formatting Rules # ############################### diff --git a/codehelp/CodeHelpers.Test/LogGenerator/LogGeneratorTest.cs b/codehelp/CodeHelpers.Test/LogGenerator/LogGeneratorTest.cs index a7b31429..354d0674 100644 --- a/codehelp/CodeHelpers.Test/LogGenerator/LogGeneratorTest.cs +++ b/codehelp/CodeHelpers.Test/LogGenerator/LogGeneratorTest.cs @@ -1,7 +1,6 @@ namespace CodeHelpers.Test.LogGenerator; using System.Text; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Testing; using Microsoft.CodeAnalysis.Testing; using Microsoft.CodeAnalysis.Text; diff --git a/codehelp/CodeHelpers.Test/LogGenerator/LogGeneratorTestVb.cs b/codehelp/CodeHelpers.Test/LogGenerator/LogGeneratorTestVb.cs index 02a6c6b9..70c39b8c 100644 --- a/codehelp/CodeHelpers.Test/LogGenerator/LogGeneratorTestVb.cs +++ b/codehelp/CodeHelpers.Test/LogGenerator/LogGeneratorTestVb.cs @@ -1,7 +1,6 @@ namespace CodeHelpers.Test.LogGenerator; using System.Text; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Testing; using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.VisualBasic.Testing; diff --git a/codehelp/CodeHelpers/IndentedStringBuilder.cs b/codehelp/CodeHelpers/IndentedStringBuilder.cs index be9dece3..9ba66cba 100644 --- a/codehelp/CodeHelpers/IndentedStringBuilder.cs +++ b/codehelp/CodeHelpers/IndentedStringBuilder.cs @@ -1,5 +1,4 @@ using System.Text; -using Microsoft.CodeAnalysis; namespace WPILib.CodeHelpers; diff --git a/codehelp/CodeHelpers/LogGenerator/LogAttributeInfo.cs b/codehelp/CodeHelpers/LogGenerator/LogAttributeInfo.cs index 9069544a..a7a99d5b 100644 --- a/codehelp/CodeHelpers/LogGenerator/LogAttributeInfo.cs +++ b/codehelp/CodeHelpers/LogGenerator/LogAttributeInfo.cs @@ -2,7 +2,6 @@ using System.Text; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.PooledObjects; using Stereologue; namespace WPILib.CodeHelpers.LogGenerator; diff --git a/codehelp/CodeHelpers/LogGenerator/LoggableType.cs b/codehelp/CodeHelpers/LogGenerator/LoggableType.cs index 3736c61a..f214bdce 100644 --- a/codehelp/CodeHelpers/LogGenerator/LoggableType.cs +++ b/codehelp/CodeHelpers/LogGenerator/LoggableType.cs @@ -4,7 +4,6 @@ using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Text; using WPILib.CodeHelpers.LogGenerator.Analyzer; -using static WPILib.CodeHelpers.IndentedStringBuilder; namespace WPILib.CodeHelpers.LogGenerator; diff --git a/codehelp/CodeHelpers/LogGenerator/SourceGenerator/LogGeneratorVb.cs b/codehelp/CodeHelpers/LogGenerator/SourceGenerator/LogGeneratorVb.cs index 484ca88b..600c4ab4 100644 --- a/codehelp/CodeHelpers/LogGenerator/SourceGenerator/LogGeneratorVb.cs +++ b/codehelp/CodeHelpers/LogGenerator/SourceGenerator/LogGeneratorVb.cs @@ -1,5 +1,4 @@ using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.VisualBasic.Syntax; namespace WPILib.CodeHelpers.LogGenerator.SourceGenerator; diff --git a/codehelp/CodeHelpers/ParameterlessStructs/Analyzer/ParameterlessStructDiagnostics.cs b/codehelp/CodeHelpers/ParameterlessStructs/Analyzer/ParameterlessStructDiagnostics.cs index 60218a86..a5ca28d5 100644 --- a/codehelp/CodeHelpers/ParameterlessStructs/Analyzer/ParameterlessStructDiagnostics.cs +++ b/codehelp/CodeHelpers/ParameterlessStructs/Analyzer/ParameterlessStructDiagnostics.cs @@ -3,8 +3,6 @@ namespace WPILib.CodeHelpers.ParameterlessStructs.Analyzer; #pragma warning disable RS2008 // Enable analyzer release tracking using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Diagnostics; -using WPILib.CodeHelpers; public static class ParameterlessStructDiagnostics { diff --git a/codehelp/CodeHelpers/SymbolExtensions.cs b/codehelp/CodeHelpers/SymbolExtensions.cs index a541bcba..c75e3bd3 100644 --- a/codehelp/CodeHelpers/SymbolExtensions.cs +++ b/codehelp/CodeHelpers/SymbolExtensions.cs @@ -1,5 +1,4 @@ using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp.Syntax; namespace WPILib.CodeHelpers; diff --git a/codehelp/CodeHelpers/TypeDeclarationModel.cs b/codehelp/CodeHelpers/TypeDeclarationModel.cs index 9cff712c..1b5bbdbd 100644 --- a/codehelp/CodeHelpers/TypeDeclarationModel.cs +++ b/codehelp/CodeHelpers/TypeDeclarationModel.cs @@ -1,5 +1,4 @@ using System.Collections.Immutable; -using System.Text; using Microsoft.CodeAnalysis; namespace WPILib.CodeHelpers; diff --git a/dev/desktopDev/Program.cs b/dev/desktopDev/Program.cs index 05fa3dbf..e4472fea 100644 --- a/dev/desktopDev/Program.cs +++ b/dev/desktopDev/Program.cs @@ -1,15 +1,10 @@ using System; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text.Json; -using CsCore; -using CsCore.Raw; using UnitsNet.NumberExtensions.NumberToAngle; using WPIHal.Natives.Simulation; using WPIMath.Geometry; -using WPIUtil; -using WPIUtil.Natives; using WPIUtil.Serialization.Struct; namespace DesktopDev; diff --git a/src/hal/CANStreamMessage.cs b/src/hal/CANStreamMessage.cs index 840d6dc3..8a66d44c 100644 --- a/src/hal/CANStreamMessage.cs +++ b/src/hal/CANStreamMessage.cs @@ -16,7 +16,11 @@ public struct CANStreamMessage [System.Runtime.CompilerServices.InlineArray(8)] public struct DataBuffer { +#pragma warning disable IDE0044 // Add readonly modifier +#pragma warning disable IDE0051 // Remove unused private members private byte _element0; +#pragma warning restore IDE0051 // Remove unused private members +#pragma warning restore IDE0044 // Add readonly modifier } } @@ -42,6 +46,10 @@ public CANMessage(ReadOnlySpan buffer, ulong timestamp) [InlineArray(8)] public struct DataBuffer { +#pragma warning disable IDE0044 // Add readonly modifier +#pragma warning disable IDE0051 // Remove unused private members private byte _element0; +#pragma warning restore IDE0051 // Remove unused private members +#pragma warning restore IDE0044 // Add readonly modifier } } diff --git a/src/hal/JoystickAxis.cs b/src/hal/JoystickAxis.cs index 879fb8d5..60178b6c 100644 --- a/src/hal/JoystickAxis.cs +++ b/src/hal/JoystickAxis.cs @@ -11,13 +11,21 @@ public readonly struct JoystickAxes [System.Runtime.CompilerServices.InlineArray(NumJoystickAxes)] public struct AxesBuffer { +#pragma warning disable IDE0044 // Add readonly modifier +#pragma warning disable IDE0051 // Remove unused private members private float _element0; +#pragma warning restore IDE0051 // Remove unused private members +#pragma warning restore IDE0044 // Add readonly modifier } [System.Runtime.CompilerServices.InlineArray(NumJoystickAxes)] public struct RawBuffer { +#pragma warning disable IDE0044 // Add readonly modifier +#pragma warning disable IDE0051 // Remove unused private members private byte _element0; +#pragma warning restore IDE0051 // Remove unused private members +#pragma warning restore IDE0044 // Add readonly modifier } private readonly short m_count; private readonly AxesBuffer m_axes; diff --git a/src/hal/JoystickDescriptor.cs b/src/hal/JoystickDescriptor.cs index 91b1c8ef..be33bbc4 100644 --- a/src/hal/JoystickDescriptor.cs +++ b/src/hal/JoystickDescriptor.cs @@ -34,7 +34,9 @@ public struct NativeJoystickDescriptor [System.Runtime.CompilerServices.InlineArray(256)] public struct NameBuffer { +#pragma warning disable IDE0044 // Add readonly modifier private byte _element0; +#pragma warning restore IDE0044 // Add readonly modifier public readonly unsafe string FromNullTerminatedString() { @@ -49,7 +51,11 @@ public readonly unsafe string FromNullTerminatedString() [System.Runtime.CompilerServices.InlineArray(12)] public struct AxesTypeBuffer { +#pragma warning disable IDE0044 // Add readonly modifier +#pragma warning disable IDE0051 // Remove unused private members private byte _element0; +#pragma warning restore IDE0051 // Remove unused private members +#pragma warning restore IDE0044 // Add readonly modifier public readonly unsafe int[] FromRawBytes(int length) { diff --git a/src/hal/JoystickPOVs.cs b/src/hal/JoystickPOVs.cs index 8e0ba34a..4cf39ca1 100644 --- a/src/hal/JoystickPOVs.cs +++ b/src/hal/JoystickPOVs.cs @@ -11,7 +11,11 @@ public readonly struct JoystickPOVs [System.Runtime.CompilerServices.InlineArray(NumJoystickPOVs)] public struct PovsBuffer { +#pragma warning disable IDE0044 // Add readonly modifier +#pragma warning disable IDE0051 // Remove unused private members private short _element0; +#pragma warning restore IDE0051 // Remove unused private members +#pragma warning restore IDE0044 // Add readonly modifier } private readonly short m_count; diff --git a/src/hal/Natives/Simulation/HalAccelerometerData.cs b/src/hal/Natives/Simulation/HalAccelerometerData.cs index b9f4a6c0..ffb9c81b 100644 --- a/src/hal/Natives/Simulation/HalAccelerometerData.cs +++ b/src/hal/Natives/Simulation/HalAccelerometerData.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]; using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]; namespace WPIHal.Natives.Simulation; diff --git a/src/hal/Natives/Simulation/HalAddressableLEDData.cs b/src/hal/Natives/Simulation/HalAddressableLEDData.cs index 65782857..ee67bf61 100644 --- a/src/hal/Natives/Simulation/HalAddressableLEDData.cs +++ b/src/hal/Natives/Simulation/HalAddressableLEDData.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]; using unsafe HAL_ConstBufferCallback = delegate* unmanaged[Cdecl]; using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]; diff --git a/src/hal/Natives/Simulation/HalAnalogGyroData.cs b/src/hal/Natives/Simulation/HalAnalogGyroData.cs index abc9c49e..c33d8722 100644 --- a/src/hal/Natives/Simulation/HalAnalogGyroData.cs +++ b/src/hal/Natives/Simulation/HalAnalogGyroData.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]; using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]; namespace WPIHal.Natives.Simulation; diff --git a/src/hal/Natives/Simulation/HalAnalogInData.cs b/src/hal/Natives/Simulation/HalAnalogInData.cs index ce4b4173..42a225b4 100644 --- a/src/hal/Natives/Simulation/HalAnalogInData.cs +++ b/src/hal/Natives/Simulation/HalAnalogInData.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]; using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]; namespace WPIHal.Natives.Simulation; diff --git a/src/hal/Natives/Simulation/HalAnalogOutData.cs b/src/hal/Natives/Simulation/HalAnalogOutData.cs index 46e69ffe..ea378feb 100644 --- a/src/hal/Natives/Simulation/HalAnalogOutData.cs +++ b/src/hal/Natives/Simulation/HalAnalogOutData.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]; using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]; namespace WPIHal.Natives.Simulation; diff --git a/src/hal/Natives/Simulation/HalAnalogTriggerData.cs b/src/hal/Natives/Simulation/HalAnalogTriggerData.cs index 64971b4d..4e548098 100644 --- a/src/hal/Natives/Simulation/HalAnalogTriggerData.cs +++ b/src/hal/Natives/Simulation/HalAnalogTriggerData.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]; using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]; namespace WPIHal.Natives.Simulation; diff --git a/src/hal/Natives/Simulation/HalCTREPCMData.cs b/src/hal/Natives/Simulation/HalCTREPCMData.cs index 0e42ed83..fa90f79b 100644 --- a/src/hal/Natives/Simulation/HalCTREPCMData.cs +++ b/src/hal/Natives/Simulation/HalCTREPCMData.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]; using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]; namespace WPIHal.Natives.Simulation; diff --git a/src/hal/Natives/Simulation/HalDIOData.cs b/src/hal/Natives/Simulation/HalDIOData.cs index e00f6af5..f032fc70 100644 --- a/src/hal/Natives/Simulation/HalDIOData.cs +++ b/src/hal/Natives/Simulation/HalDIOData.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]; using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]; namespace WPIHal.Natives.Simulation; diff --git a/src/hal/Natives/Simulation/HalDigitalPWMData.cs b/src/hal/Natives/Simulation/HalDigitalPWMData.cs index ce43979f..dc27e47b 100644 --- a/src/hal/Natives/Simulation/HalDigitalPWMData.cs +++ b/src/hal/Natives/Simulation/HalDigitalPWMData.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]; using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]; namespace WPIHal.Natives.Simulation; diff --git a/src/hal/Natives/Simulation/HalDutyCycleData.cs b/src/hal/Natives/Simulation/HalDutyCycleData.cs index 211916ae..2e1f0d0d 100644 --- a/src/hal/Natives/Simulation/HalDutyCycleData.cs +++ b/src/hal/Natives/Simulation/HalDutyCycleData.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]; using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]; namespace WPIHal.Natives.Simulation; diff --git a/src/hal/Natives/Simulation/HalEncoderData.cs b/src/hal/Natives/Simulation/HalEncoderData.cs index 9653816d..ddc6e2c4 100644 --- a/src/hal/Natives/Simulation/HalEncoderData.cs +++ b/src/hal/Natives/Simulation/HalEncoderData.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]; using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]; namespace WPIHal.Natives.Simulation; diff --git a/src/hal/Natives/Simulation/HalNotifierData.cs b/src/hal/Natives/Simulation/HalNotifierData.cs index 2f102cfa..6c283bed 100644 --- a/src/hal/Natives/Simulation/HalNotifierData.cs +++ b/src/hal/Natives/Simulation/HalNotifierData.cs @@ -1,7 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]; -using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]; namespace WPIHal.Natives.Simulation; diff --git a/src/hal/Natives/Simulation/HalPWMData.cs b/src/hal/Natives/Simulation/HalPWMData.cs index 935ffae6..e1622893 100644 --- a/src/hal/Natives/Simulation/HalPWMData.cs +++ b/src/hal/Natives/Simulation/HalPWMData.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]; using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]; namespace WPIHal.Natives.Simulation; diff --git a/src/hal/Natives/Simulation/HalPowerDistributionData.cs b/src/hal/Natives/Simulation/HalPowerDistributionData.cs index c492ab94..c94e183f 100644 --- a/src/hal/Natives/Simulation/HalPowerDistributionData.cs +++ b/src/hal/Natives/Simulation/HalPowerDistributionData.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]; using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]; namespace WPIHal.Natives.Simulation; diff --git a/src/hal/Natives/Simulation/HalREVPHData.cs b/src/hal/Natives/Simulation/HalREVPHData.cs index 5b3d9989..a5e94274 100644 --- a/src/hal/Natives/Simulation/HalREVPHData.cs +++ b/src/hal/Natives/Simulation/HalREVPHData.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]; using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]; namespace WPIHal.Natives.Simulation; diff --git a/src/hal/Natives/Simulation/HalRelayData.cs b/src/hal/Natives/Simulation/HalRelayData.cs index 146420d9..c5018bda 100644 --- a/src/hal/Natives/Simulation/HalRelayData.cs +++ b/src/hal/Natives/Simulation/HalRelayData.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]; using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]; namespace WPIHal.Natives.Simulation; diff --git a/src/hal/Natives/Simulation/HalSPIAccelerometerData.cs b/src/hal/Natives/Simulation/HalSPIAccelerometerData.cs index 01ebd239..32a56ea4 100644 --- a/src/hal/Natives/Simulation/HalSPIAccelerometerData.cs +++ b/src/hal/Natives/Simulation/HalSPIAccelerometerData.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]; using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]; namespace WPIHal.Natives.Simulation; diff --git a/src/hal/Natives/Simulation/NotifyListener.cs b/src/hal/Natives/Simulation/NotifyListener.cs index 7b85497f..102eb205 100644 --- a/src/hal/Natives/Simulation/NotifyListener.cs +++ b/src/hal/Natives/Simulation/NotifyListener.cs @@ -1,8 +1,3 @@ -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]; -using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]; - namespace WPIHal.Natives.Simulation; public static unsafe partial class HalNotifyListener diff --git a/src/hal/Natives/Simulation/Reset.cs b/src/hal/Natives/Simulation/Reset.cs index 3b3ee936..a608de16 100644 --- a/src/hal/Natives/Simulation/Reset.cs +++ b/src/hal/Natives/Simulation/Reset.cs @@ -1,7 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using unsafe HAL_BufferCallback = delegate* unmanaged[Cdecl]; -using unsafe HAL_NotifyCallback = delegate* unmanaged[Cdecl]; namespace WPIHal.Natives.Simulation; diff --git a/src/newcommands/Command.cs b/src/newcommands/Command.cs index f51b82b3..7a2b2138 100644 --- a/src/newcommands/Command.cs +++ b/src/newcommands/Command.cs @@ -1,5 +1,3 @@ -using System; -using System.Collections.Generic; using CommunityToolkit.Diagnostics; using WPIUtil.Sendable; diff --git a/src/newcommands/ConditionalCommand.cs b/src/newcommands/ConditionalCommand.cs index 46ffae57..6c1caf3c 100644 --- a/src/newcommands/ConditionalCommand.cs +++ b/src/newcommands/ConditionalCommand.cs @@ -6,7 +6,9 @@ public class ConditionalCommand : Command { private readonly Command m_onTrue; private readonly Command m_onFalse; +#pragma warning disable IDE0052 // Remove unread private members private readonly Func m_condition; +#pragma warning restore IDE0052 // Remove unread private members public ConditionalCommand(Command onTrue, Command onFalse, Func condition) { diff --git a/src/newcommands/DeferredCommand.cs b/src/newcommands/DeferredCommand.cs index a8f58279..65b524d8 100644 --- a/src/newcommands/DeferredCommand.cs +++ b/src/newcommands/DeferredCommand.cs @@ -6,8 +6,10 @@ public class DeferredCommand : Command { private readonly Command m_nullCommand = new PrintCommand("[DeferredCommand] Supplied command was null!"); +#pragma warning disable IDE0052 // Remove unread private members private readonly Func m_supplier; private Command m_command; +#pragma warning restore IDE0052 // Remove unread private members public DeferredCommand(Func supplier, HashSet requirements) { diff --git a/src/ntcore/ConnectionInfo.cs b/src/ntcore/ConnectionInfo.cs index 3e5c3c24..6a8b6e16 100644 --- a/src/ntcore/ConnectionInfo.cs +++ b/src/ntcore/ConnectionInfo.cs @@ -1,8 +1,9 @@ using System.Runtime.InteropServices; using System.Runtime.InteropServices.Marshalling; +using NetworkTables.Natives; using WPIUtil.Marshal; -namespace NetworkTables.Natives; +namespace NetworkTables; [NativeMarshalling(typeof(ConnectionInfoMarshaller))] [StructLayout(LayoutKind.Auto)] diff --git a/src/ntcore/NetworkTable.cs b/src/ntcore/NetworkTable.cs index 584ae028..40c42518 100644 --- a/src/ntcore/NetworkTable.cs +++ b/src/ntcore/NetworkTable.cs @@ -1,6 +1,5 @@ using System.Collections.Concurrent; using NetworkTables.Handles; -using NetworkTables.Natives; namespace NetworkTables; diff --git a/src/ntcore/TopicInfo.cs b/src/ntcore/TopicInfo.cs index cf55af25..84cb9876 100644 --- a/src/ntcore/TopicInfo.cs +++ b/src/ntcore/TopicInfo.cs @@ -1,9 +1,10 @@ using System.Runtime.InteropServices; using System.Runtime.InteropServices.Marshalling; using NetworkTables.Handles; +using NetworkTables.Natives; using WPIUtil.Marshal; -namespace NetworkTables.Natives; +namespace NetworkTables; [NativeMarshalling(typeof(TopicInfoMarshaller))] [StructLayout(LayoutKind.Auto)] diff --git a/src/stereologue/Attributes.cs b/src/stereologue/Attributes.cs index 9ab744ae..b2206619 100644 --- a/src/stereologue/Attributes.cs +++ b/src/stereologue/Attributes.cs @@ -1,5 +1,3 @@ -using System; - namespace Stereologue; [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method | AttributeTargets.Field, Inherited = false, AllowMultiple = false)] diff --git a/src/stereologue/LogType.cs b/src/stereologue/LogType.cs index 2b25977a..67e2ecef 100644 --- a/src/stereologue/LogType.cs +++ b/src/stereologue/LogType.cs @@ -1,5 +1,3 @@ -using System; - namespace Stereologue; [Flags] diff --git a/src/stereologue/Stereologuer.cs b/src/stereologue/Stereologuer.cs index 75a2a154..aa6c3680 100644 --- a/src/stereologue/Stereologuer.cs +++ b/src/stereologue/Stereologuer.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using Google.Protobuf.WellKnownTypes; using NetworkTables; using WPIUtil.Logging; using WPIUtil.Serialization.Protobuf; @@ -18,7 +17,9 @@ private Stereologuer() { } public static Stereologuer Logger { get; } = new(); +#pragma warning disable IDE0060 // Remove unused parameter public void Setup(string name, bool fileOnly, bool lazyLogging) +#pragma warning restore IDE0060 // Remove unused parameter { rootPath = name; FileOnly = fileOnly; diff --git a/src/wpilibsharp/DataLogManager.cs b/src/wpilibsharp/DataLogManager.cs index a829af21..05fcb0eb 100644 --- a/src/wpilibsharp/DataLogManager.cs +++ b/src/wpilibsharp/DataLogManager.cs @@ -15,7 +15,11 @@ public static class DataLogManger private static string? m_logDir; private static bool m_filenameOverride; private static Thread? m_thread; +#pragma warning disable IDE0044 // Add readonly modifier +#pragma warning disable IDE0052 // Remove unread private members private static TimeZoneInfo m_utc = TimeZoneInfo.Utc; +#pragma warning restore IDE0052 // Remove unread private members +#pragma warning restore IDE0044 // Add readonly modifier private static bool m_ntLoggerEnabled = true; private static NtDataLogger m_ntEntryLogger; private static NtConnectionDataLogger m_ntConnLogger; diff --git a/src/wpilibsharp/DriverStation.cs b/src/wpilibsharp/DriverStation.cs index be5358bc..138deeb6 100644 --- a/src/wpilibsharp/DriverStation.cs +++ b/src/wpilibsharp/DriverStation.cs @@ -340,10 +340,14 @@ public void Send(long timestamp) private static MatchInfo m_matchInfoCache; private static ControlWord m_controlWordCache; - private static EventVector m_refreshEvents = new(); + private static readonly EventVector m_refreshEvents = new(); - private static int[] m_joystickButtonsPressed = new int[NumJoystickPorts]; - private static int[] m_joystickButtonsReleased = new int[NumJoystickPorts]; +#pragma warning disable IDE0052 // Remove unread private members + private static readonly int[] m_joystickButtonsPressed = new int[NumJoystickPorts]; +#pragma warning restore IDE0052 // Remove unread private members +#pragma warning disable IDE0052 // Remove unread private members + private static readonly int[] m_joystickButtonsReleased = new int[NumJoystickPorts]; +#pragma warning restore IDE0052 // Remove unread private members private static readonly MatchDataSender m_matchDataSender; private static DataLogSender? m_dataLogSender; @@ -383,7 +387,7 @@ private static void ReportJoystickUnpluggedWarning(string message) public static bool GetStickButton(int stick, int button) { - if (stick < 0 || stick >= NumJoystickPorts) + if (stick is < 0 or >= NumJoystickPorts) { ThrowHelper.ThrowArgumentOutOfRangeException(nameof(stick), $"Joystick index {stick} is out of range, should be 0-5"); } @@ -409,12 +413,12 @@ public static bool GetStickButton(int stick, int button) public static double GetStickAxis(int stick, int axis) { - if (stick < 0 || stick >= NumJoystickPorts) + if (stick is < 0 or >= NumJoystickPorts) { ThrowHelper.ThrowArgumentOutOfRangeException(nameof(stick), $"Joystick index {stick} is out of range, should be 0-5"); } - if (axis < 0 || axis >= JoystickAxes.NumJoystickAxes) + if (axis is < 0 or >= JoystickAxes.NumJoystickAxes) { ThrowHelper.ThrowArgumentOutOfRangeException(nameof(axis), $"Joystick axis {axis} is out of range"); } @@ -434,12 +438,12 @@ public static double GetStickAxis(int stick, int axis) public static int GetStickPOV(int stick, int pov) { - if (stick < 0 || stick >= NumJoystickPorts) + if (stick is < 0 or >= NumJoystickPorts) { ThrowHelper.ThrowArgumentOutOfRangeException(nameof(stick), $"Joystick index {stick} is out of range, should be 0-5"); } - if (pov < 0 || pov >= JoystickPOVs.NumJoystickPOVs) + if (pov is < 0 or >= JoystickPOVs.NumJoystickPOVs) { ThrowHelper.ThrowArgumentOutOfRangeException(nameof(pov), $"Joystick pov {pov} is out of range"); } @@ -459,7 +463,7 @@ public static int GetStickPOV(int stick, int pov) public static uint GetStickButtons(int stick) { - if (stick < 0 || stick >= NumJoystickPorts) + if (stick is < 0 or >= NumJoystickPorts) { ThrowHelper.ThrowArgumentOutOfRangeException(nameof(stick), $"Joystick index {stick} is out of range, should be 0-5"); } @@ -472,7 +476,7 @@ public static uint GetStickButtons(int stick) public static int GetStickAxisCount(int stick) { - if (stick < 0 || stick >= NumJoystickPorts) + if (stick is < 0 or >= NumJoystickPorts) { ThrowHelper.ThrowArgumentOutOfRangeException(nameof(stick), $"Joystick index {stick} is out of range, should be 0-5"); } @@ -485,7 +489,7 @@ public static int GetStickAxisCount(int stick) public static int GetStickPOVCount(int stick) { - if (stick < 0 || stick >= NumJoystickPorts) + if (stick is < 0 or >= NumJoystickPorts) { ThrowHelper.ThrowArgumentOutOfRangeException(nameof(stick), $"Joystick index {stick} is out of range, should be 0-5"); } @@ -498,7 +502,7 @@ public static int GetStickPOVCount(int stick) public static int GetStickButtonCount(int stick) { - if (stick < 0 || stick >= NumJoystickPorts) + if (stick is < 0 or >= NumJoystickPorts) { ThrowHelper.ThrowArgumentOutOfRangeException(nameof(stick), $"Joystick index {stick} is out of range, should be 0-5"); } @@ -511,7 +515,7 @@ public static int GetStickButtonCount(int stick) public static bool GetJoystickIsXbox(int stick) { - if (stick < 0 || stick >= NumJoystickPorts) + if (stick is < 0 or >= NumJoystickPorts) { ThrowHelper.ThrowArgumentOutOfRangeException(nameof(stick), $"Joystick index {stick} is out of range, should be 0-5"); } @@ -521,7 +525,7 @@ public static bool GetJoystickIsXbox(int stick) public static int GetJoystickType(int stick) { - if (stick < 0 || stick >= NumJoystickPorts) + if (stick is < 0 or >= NumJoystickPorts) { ThrowHelper.ThrowArgumentOutOfRangeException(nameof(stick), $"Joystick index {stick} is out of range, should be 0-5"); } @@ -531,7 +535,7 @@ public static int GetJoystickType(int stick) public static string GetJoystickName(int stick) { - if (stick < 0 || stick >= NumJoystickPorts) + if (stick is < 0 or >= NumJoystickPorts) { ThrowHelper.ThrowArgumentOutOfRangeException(nameof(stick), $"Joystick index {stick} is out of range, should be 0-5"); } @@ -542,7 +546,7 @@ public static string GetJoystickName(int stick) public static int GetJoystickAxisType(int stick, int axis) { - if (stick < 0 || stick >= NumJoystickPorts) + if (stick is < 0 or >= NumJoystickPorts) { ThrowHelper.ThrowArgumentOutOfRangeException(nameof(stick), $"Joystick index {stick} is out of range, should be 0-5"); } @@ -834,12 +838,12 @@ public static void RefreshData() dataLogSender?.Send((long)TimestampNative.Now()); } - public static void ReportWarning(string warning, bool printTrace) + public static void ReportWarning(string _, bool __) { } - public static void ReportError(string warning, bool printTrace) + public static void ReportError(string _, bool __) { } diff --git a/src/wpilibsharp/IterativeRobotBase.cs b/src/wpilibsharp/IterativeRobotBase.cs index 1eea17ba..4078a3f3 100644 --- a/src/wpilibsharp/IterativeRobotBase.cs +++ b/src/wpilibsharp/IterativeRobotBase.cs @@ -1,7 +1,6 @@ using CommunityToolkit.Diagnostics; using NetworkTables; using UnitsNet; -using WPIHal; using WPIHal.Natives; namespace WPILib; diff --git a/src/wpilibsharp/Notifier.cs b/src/wpilibsharp/Notifier.cs index 9b4e58ef..2da27e92 100644 --- a/src/wpilibsharp/Notifier.cs +++ b/src/wpilibsharp/Notifier.cs @@ -31,7 +31,7 @@ public void Dispose() } HalNotifier.StopNotifier(handle); - if (m_thread.IsAlive == true) + if (m_thread.IsAlive) { m_thread.Interrupt(); m_thread.Join(); diff --git a/src/wpilibsharp/RobotBase.cs b/src/wpilibsharp/RobotBase.cs index 6ea36050..7bfbfc7a 100644 --- a/src/wpilibsharp/RobotBase.cs +++ b/src/wpilibsharp/RobotBase.cs @@ -1,5 +1,3 @@ -using System.Runtime.ConstrainedExecution; -using CommunityToolkit.Diagnostics; using NetworkTables; using WPIHal.Natives; @@ -55,7 +53,7 @@ public static bool IsReal get { var rt = RuntimeType; - return rt == RuntimeType.RoboRIO || rt == RuntimeType.RoboRIO2; + return rt is RuntimeType.RoboRIO or RuntimeType.RoboRIO2; } } diff --git a/src/wpilibsharp/RobotController.cs b/src/wpilibsharp/RobotController.cs index 7267a240..14d67704 100644 --- a/src/wpilibsharp/RobotController.cs +++ b/src/wpilibsharp/RobotController.cs @@ -4,7 +4,6 @@ using UnitsNet.NumberExtensions.NumberToTemperature; using WPIHal; using WPIHal.Natives; -using WPIHal.Natives.Simulation; namespace WPILib; diff --git a/src/wpilibsharp/Simulation/AddressableLEDSim.cs b/src/wpilibsharp/Simulation/AddressableLEDSim.cs index 73a842c3..2e83570b 100644 --- a/src/wpilibsharp/Simulation/AddressableLEDSim.cs +++ b/src/wpilibsharp/Simulation/AddressableLEDSim.cs @@ -1,6 +1,5 @@ using CommunityToolkit.Diagnostics; using CommunityToolkit.HighPerformance; -using WPIHal; using WPIHal.Natives; using WPIHal.Natives.Simulation; @@ -15,7 +14,7 @@ public AddressableLEDSim() m_index = 0; } - public AddressableLEDSim(AddressableLED addressableLED) + public AddressableLEDSim(AddressableLED _) { m_index = 0; } diff --git a/src/wpilibsharp/Simulation/CallbackStore.cs b/src/wpilibsharp/Simulation/CallbackStore.cs index 77334376..68428c23 100644 --- a/src/wpilibsharp/Simulation/CallbackStore.cs +++ b/src/wpilibsharp/Simulation/CallbackStore.cs @@ -6,7 +6,6 @@ using unsafe HalGlobalFree = delegate* managed; using unsafe HalIndexedCreate = delegate* managed, void*, bool, int>; using unsafe HalIndexedFree = delegate* managed; -using unsafe HalNativeNotifyCallback = delegate* unmanaged[Cdecl]; namespace WPILib.Simulation; diff --git a/src/wpilibsharp/Watchdog.cs b/src/wpilibsharp/Watchdog.cs index a9eed7d9..00fcf756 100644 --- a/src/wpilibsharp/Watchdog.cs +++ b/src/wpilibsharp/Watchdog.cs @@ -1,4 +1,3 @@ -using System.Runtime.CompilerServices; using UnitsNet; using UnitsNet.NumberExtensions.NumberToDuration; using WPIHal.Handles; diff --git a/src/wpimath/MathSharedStore.cs b/src/wpimath/MathSharedStore.cs index a24b65d5..25303da2 100644 --- a/src/wpimath/MathSharedStore.cs +++ b/src/wpimath/MathSharedStore.cs @@ -28,10 +28,7 @@ public static IMathShared MathShared { lock (m_lockObject) { - if (m_mathShared == null) - { - m_mathShared = new DefaultMathShared(); - } + m_mathShared ??= new DefaultMathShared(); return m_mathShared; } } diff --git a/src/wpiutil/Concurrent/Event.cs b/src/wpiutil/Concurrent/Event.cs index 58ebcdbb..86e8b050 100644 --- a/src/wpiutil/Concurrent/Event.cs +++ b/src/wpiutil/Concurrent/Event.cs @@ -1,4 +1,3 @@ -using System.Runtime.InteropServices.Marshalling; using WPIUtil.Handles; using WPIUtil.Natives; diff --git a/src/wpiutil/Concurrent/Synchronization.cs b/src/wpiutil/Concurrent/Synchronization.cs index d3acf0c1..0dc04a09 100644 --- a/src/wpiutil/Concurrent/Synchronization.cs +++ b/src/wpiutil/Concurrent/Synchronization.cs @@ -1,4 +1,3 @@ -using System.Runtime.InteropServices.Marshalling; using CommunityToolkit.Diagnostics; using UnitsNet; using WPIUtil.Handles; diff --git a/src/wpiutil/Logging/DataLog.cs b/src/wpiutil/Logging/DataLog.cs index 7375dd6c..2b212437 100644 --- a/src/wpiutil/Logging/DataLog.cs +++ b/src/wpiutil/Logging/DataLog.cs @@ -44,6 +44,7 @@ public bool HasSchema(string name) return m_schemaMap.ContainsKey(name); } +#pragma warning disable IDE0060 // Remove unused parameter private void AddSchemaNative(string name, WpiString type, WpiString schema, long timestamp = 0) { if (!m_schemaMap.TryAdd(name, 1)) @@ -81,7 +82,7 @@ public void AddSchema(IStructBase value, long timestamp = 0) public void AddSchema(IProtobuf proto, long timestamp = 0) { - long actualTimestamp = timestamp == 0 ? (long)TimestampNative.Now() : timestamp; + var actualTimestamp = timestamp == 0 ? (long)TimestampNative.Now() : timestamp; proto.ForEachDescriptor(HasSchema, (typeString, schema) => { AddSchemaNative(typeString, "proto:FileDescriptorProto"u8, schema, actualTimestamp); @@ -175,7 +176,7 @@ public void AppendStringArray(DataLogEntryHandle entry, ReadOnlySpan val private void AddSchemaImpl(IStructBase value, long timestamp, HashSet seen) { - string typeString = value.TypeString; + var typeString = value.TypeString; if (HasSchema(typeString)) { return; diff --git a/src/wpiutil/Natives/SynchronizationNative.cs b/src/wpiutil/Natives/SynchronizationNative.cs index 57dcea49..98786d51 100644 --- a/src/wpiutil/Natives/SynchronizationNative.cs +++ b/src/wpiutil/Natives/SynchronizationNative.cs @@ -1,11 +1,10 @@ -namespace WPIUtil.Natives; - -using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using CommunityToolkit.Diagnostics; using WPIUtil.Handles; +namespace WPIUtil.Natives; + public static partial class SynchronizationNative { [LibraryImport("wpiutil", EntryPoint = "WPI_CreateEvent")] diff --git a/src/wpiutil/Serialization/Struct/Parsing/Parser.cs b/src/wpiutil/Serialization/Struct/Parsing/Parser.cs index 18979b9c..8bd86df5 100644 --- a/src/wpiutil/Serialization/Struct/Parsing/Parser.cs +++ b/src/wpiutil/Serialization/Struct/Parsing/Parser.cs @@ -149,7 +149,7 @@ private TokenKind GetNextToken() return m_token; } - private void Expect(TokenKind kind) + private readonly void Expect(TokenKind kind) { if (m_token != kind) {