diff --git a/.editorconfig b/.editorconfig index 7d20e56..6916bef 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,6 +1,13 @@ # Remove the line below if you want to inherit .editorconfig settings from higher directories root = true +# Test .cs files +[**/*Tests.cs] + +# This doesn't work well with TheoryData +# CA1861: Avoid constant arrays as arguments +dotnet_diagnostic.CA1861.severity = none + # Native .cs files [**/Win32/**/*.cs] @@ -22,9 +29,13 @@ dotnet_diagnostic.SA1313.severity = none # IDE1006: Naming Styles dotnet_diagnostic.IDE1006.severity = none -# CS0649: +# CS0649: dotnet_diagnostic.CS0649.severity = none +[**/Interop.**.cs] +# SA1313: Parameter names should begin with lower-case letter +dotnet_diagnostic.SA1313.severity = none + # C# files [*.cs] @@ -388,6 +399,9 @@ csharp_style_prefer_pattern_matching = true:silent csharp_style_prefer_extended_property_pattern = true:suggestion csharp_style_prefer_not_pattern = true:suggestion +# SYSLIB1096: Convert to 'GeneratedComInterface' +dotnet_diagnostic.SYSLIB1096.severity = none + [*.{cs,vb}] dotnet_style_coalesce_expression = true:suggestion dotnet_style_null_propagation = true:silent diff --git a/src/samples/KeyWatch/Program.cs b/src/samples/KeyWatch/Program.cs index 000c9bb..2849259 100644 --- a/src/samples/KeyWatch/Program.cs +++ b/src/samples/KeyWatch/Program.cs @@ -42,7 +42,7 @@ protected override LRESULT WindowProcedure(HWND window, MessageType message, WPA switch (message) { case MessageType.KeyUp: - Message.KeyUpDown key = new(wParam, lParam); + Message.KeyUpDown key = new(wParam); Debug.WriteLine($"KeyUp: {key.Key}"); break; case MessageType.KeyDown: diff --git a/src/thirtytwo/Application.cs b/src/thirtytwo/Application.cs index 9773400..19ed7a6 100644 --- a/src/thirtytwo/Application.cs +++ b/src/thirtytwo/Application.cs @@ -75,8 +75,7 @@ public static void Run( string? windowTitle = null, WindowStyles style = WindowStyles.OverlappedWindow, ExtendedWindowStyles extendedStyle = ExtendedWindowStyles.Default, - HMENU menuHandle = default) - => Run( + HMENU menuHandle = default) => Run( windowClass, Window.DefaultBounds, windowTitle, diff --git a/src/thirtytwo/CharacterSet.cs b/src/thirtytwo/CharacterSet.cs index bfc92ec..48d4c53 100644 --- a/src/thirtytwo/CharacterSet.cs +++ b/src/thirtytwo/CharacterSet.cs @@ -10,7 +10,6 @@ public enum CharacterSet : byte Symbol = FONT_CHARSET.SYMBOL_CHARSET, Mac = FONT_CHARSET.MAC_CHARSET, ShiftJis = FONT_CHARSET.SHIFTJIS_CHARSET, - Hangeul = FONT_CHARSET.HANGEUL_CHARSET, Hangul = FONT_CHARSET.HANGUL_CHARSET, GB2312 = FONT_CHARSET.GB2312_CHARSET, ChineseBig5 = FONT_CHARSET.CHINESEBIG5_CHARSET, diff --git a/src/thirtytwo/Clipboard.cs b/src/thirtytwo/Clipboard.cs index f29ad96..5be3214 100644 --- a/src/thirtytwo/Clipboard.cs +++ b/src/thirtytwo/Clipboard.cs @@ -27,7 +27,7 @@ public static unsafe uint[] GetAvailableClipboardFormats() uint count = (uint)Interop.CountClipboardFormats(); if (count == 0) { - return Array.Empty(); + return []; } using BufferScope buffer = new(stackalloc uint[(int)count]); @@ -42,7 +42,7 @@ public static unsafe uint[] GetAvailableClipboardFormats() buffer.EnsureCapacity((int)count); } while (true); - return count == 0 ? Array.Empty() : buffer[..(int)count].ToArray(); + return count == 0 ? [] : buffer[..(int)count].ToArray(); } /// diff --git a/src/thirtytwo/Controls/ButtonControl.Styles.cs b/src/thirtytwo/Controls/ButtonControl.Styles.cs index 0987238..fd0620d 100644 --- a/src/thirtytwo/Controls/ButtonControl.Styles.cs +++ b/src/thirtytwo/Controls/ButtonControl.Styles.cs @@ -94,14 +94,18 @@ public enum Styles : uint /// /// Draw text to the left of radio buttons and checkboxes. - /// Same as RightButton. /// + /// + /// Same as . + /// LeftText = Interop.BS_LEFTTEXT, /// /// Draw text to the left of radio buttons and checkboxes. - /// Same as LeftText /// + /// + /// Same as . + /// RightButton = Interop.BS_RIGHTBUTTON, // This is the default state- buttons have text diff --git a/src/thirtytwo/DrawTextFormat.cs b/src/thirtytwo/DrawTextFormat.cs index 17a70cb..209f098 100644 --- a/src/thirtytwo/DrawTextFormat.cs +++ b/src/thirtytwo/DrawTextFormat.cs @@ -3,8 +3,6 @@ namespace Windows; -#pragma warning disable CA1069 // Enums values should not be duplicated - [Flags] public enum DrawTextFormat : uint { @@ -32,6 +30,4 @@ public enum DrawTextFormat : uint NoFullWidthCharacterBreak = DRAW_TEXT_FORMAT.DT_NOFULLWIDTHCHARBREAK, HidePrefix = DRAW_TEXT_FORMAT.DT_HIDEPREFIX, PrefixOnly = DRAW_TEXT_FORMAT.DT_PREFIXONLY -} - -#pragma warning restore CA1069 // Enums values should not be duplicated \ No newline at end of file +} \ No newline at end of file diff --git a/src/thirtytwo/ExtendedWindowStyles.cs b/src/thirtytwo/ExtendedWindowStyles.cs index ae12111..19d8c9a 100644 --- a/src/thirtytwo/ExtendedWindowStyles.cs +++ b/src/thirtytwo/ExtendedWindowStyles.cs @@ -2,7 +2,6 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. namespace Windows; -#pragma warning disable CA1069 // Enums values should not be duplicated [Flags] public enum ExtendedWindowStyles : uint @@ -136,6 +135,4 @@ public enum ExtendedWindowStyles : uint /// user clicks it. /// NoActivate = WINDOW_EX_STYLE.WS_EX_NOACTIVATE -} - -#pragma warning restore CA1069 // Enums values should not be duplicated \ No newline at end of file +} \ No newline at end of file diff --git a/src/thirtytwo/GlobalSuppressions.cs b/src/thirtytwo/GlobalSuppressions.cs new file mode 100644 index 0000000..cdfce56 --- /dev/null +++ b/src/thirtytwo/GlobalSuppressions.cs @@ -0,0 +1,14 @@ +// Copyright (c) Jeremy W. Kuhne. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "type", Target = "~T:Windows.ButtonControl.Styles")] +[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "member", Target = "~F:Windows.FontWeight.Black")] +[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "type", Target = "~T:Windows.FontWeight")] +[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "type", Target = "~T:Windows.SystemColor")] +[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "type", Target = "~T:Windows.StockBrush")] +[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "type", Target = "~T:Windows.ExtendedWindowStyles")] +[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "type", Target = "~T:Windows.DrawTextFormat")] +[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "type", Target = "~T:Windows.IconId")] +[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "type", Target = "~T:Windows.MessageBoxStyles")] +[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "type", Target = "~T:Windows.WindowStyles")] +[assembly: SuppressMessage("Usage", "CA2231:Overload operator equals on overriding value type Equals", Justification = "CsWin32", Scope = "type", Target = "~T:Windows.Win32.Foundation.PCWSTR")] \ No newline at end of file diff --git a/src/thirtytwo/Messages/Message.KeyUpDown.cs b/src/thirtytwo/Messages/Message.KeyUpDown.cs index 7d34186..4a5dcb9 100644 --- a/src/thirtytwo/Messages/Message.KeyUpDown.cs +++ b/src/thirtytwo/Messages/Message.KeyUpDown.cs @@ -7,9 +7,7 @@ namespace Windows; public static partial class Message { -#pragma warning disable CS9113 // LPARAM is needed for other details, just haven't implemented yet. - public readonly ref struct KeyUpDown(WPARAM wParam, LPARAM lParam) -#pragma warning restore CS9113 + public readonly ref struct KeyUpDown(WPARAM wParam) { public VIRTUAL_KEY Key { get; } = (VIRTUAL_KEY)(nuint)wParam; } diff --git a/src/thirtytwo/Messages/Message.Timer.cs b/src/thirtytwo/Messages/Message.Timer.cs index cc19fca..f4837c2 100644 --- a/src/thirtytwo/Messages/Message.Timer.cs +++ b/src/thirtytwo/Messages/Message.Timer.cs @@ -7,11 +7,9 @@ public static partial class Message { public readonly ref struct Timer(WPARAM wParam, LPARAM lParam) { - private readonly WPARAM _wParam = wParam; - private readonly LPARAM _lParam = lParam; - - public uint Id => (uint)_wParam; + public uint Id => (uint)wParam; + public nint Procedure => lParam; // public TimerProcedure? Procedure // => _lParam.IsNull ? null : Marshal.GetDelegateForFunctionPointer(_lParam); } diff --git a/src/thirtytwo/StockBrush.cs b/src/thirtytwo/StockBrush.cs index 3da77d4..851583a 100644 --- a/src/thirtytwo/StockBrush.cs +++ b/src/thirtytwo/StockBrush.cs @@ -11,9 +11,7 @@ public enum StockBrush : uint DarkGray = GET_STOCK_OBJECT_FLAGS.DKGRAY_BRUSH, Black = GET_STOCK_OBJECT_FLAGS.BLACK_BRUSH, Hollow = GET_STOCK_OBJECT_FLAGS.HOLLOW_BRUSH, -#pragma warning disable CA1069 // Enums values should not be duplicated Null = GET_STOCK_OBJECT_FLAGS.NULL_BRUSH, -#pragma warning restore CA1069 /// /// Device context brush. Color is changed via Get/SetDeviceContextBrushColor. diff --git a/src/thirtytwo/Support/SpanWriter.cs b/src/thirtytwo/Support/SpanWriter.cs index c3ea72c..73667cf 100644 --- a/src/thirtytwo/Support/SpanWriter.cs +++ b/src/thirtytwo/Support/SpanWriter.cs @@ -96,12 +96,14 @@ private void UnsafeAdvance(int count) UncheckedSlice(ref _unwritten, count, _unwritten.Length - count); } + /* [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void UncheckedSliceTo(ref Span span, int length) { Debug.Assert((uint)length <= (uint)span.Length); span = MemoryMarshal.CreateSpan(ref MemoryMarshal.GetReference(span), length); } + */ [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void UncheckedSlice(ref Span span, int start, int length) diff --git a/src/thirtytwo/Support/TempFolder.cs b/src/thirtytwo/Support/TempFolder.cs index 66ea2ef..21676d7 100644 --- a/src/thirtytwo/Support/TempFolder.cs +++ b/src/thirtytwo/Support/TempFolder.cs @@ -5,7 +5,7 @@ namespace Windows.Support; -public class TempFolder : IDisposable +public sealed class TempFolder : IDisposable { public string Path { get; } = IO.Path.Join(IO.Path.GetTempPath(), IO.Path.GetRandomFileName()); diff --git a/src/thirtytwo/SystemColor.cs b/src/thirtytwo/SystemColor.cs index fcdc96f..4e4cbb2 100644 --- a/src/thirtytwo/SystemColor.cs +++ b/src/thirtytwo/SystemColor.cs @@ -71,7 +71,6 @@ public enum SystemColor : int MenuBar = SYS_COLOR_INDEX.COLOR_MENUBAR, -#pragma warning disable CA1069 // Enums values should not be duplicated Desktop = SYS_COLOR_INDEX.COLOR_DESKTOP, Face3d = SYS_COLOR_INDEX.COLOR_3DFACE, @@ -79,5 +78,4 @@ public enum SystemColor : int Shadow3d = SYS_COLOR_INDEX.COLOR_3DSHADOW, Highlight3d = SYS_COLOR_INDEX.COLOR_3DHIGHLIGHT -#pragma warning restore CA1069 // Enums values should not be duplicated } \ No newline at end of file diff --git a/src/thirtytwo/Wdk/Interop.cs b/src/thirtytwo/Wdk/Interop.NtQueryKey.cs similarity index 90% rename from src/thirtytwo/Wdk/Interop.cs rename to src/thirtytwo/Wdk/Interop.NtQueryKey.cs index f73d97e..a462c0a 100644 --- a/src/thirtytwo/Wdk/Interop.cs +++ b/src/thirtytwo/Wdk/Interop.NtQueryKey.cs @@ -7,8 +7,6 @@ namespace Windows.Wdk; -#pragma warning disable SA1313 // Parameter names should begin with lower-case letter - public static partial class Interop { /// @@ -34,6 +32,4 @@ public static extern unsafe NTSTATUS NtQueryKey( void* KeyInformation, uint Length, uint* ResultLength); -} - -#pragma warning restore SA1313 // Parameter names should begin with lower-case letter \ No newline at end of file +} \ No newline at end of file diff --git a/src/thirtytwo/Win32/Foundation/PCWSTR.cs b/src/thirtytwo/Win32/Foundation/PCWSTR.cs index 29a87b4..aef37ed 100644 --- a/src/thirtytwo/Win32/Foundation/PCWSTR.cs +++ b/src/thirtytwo/Win32/Foundation/PCWSTR.cs @@ -5,9 +5,7 @@ namespace Windows.Win32.Foundation; -#pragma warning disable CA2231 // Overload operator equals on overriding value type Equals public unsafe partial struct PCWSTR -#pragma warning restore CA2231 { public bool IsNull => Value is null; diff --git a/src/thirtytwo/Win32/System/Com/ComTypeDescriptor.cs b/src/thirtytwo/Win32/System/Com/ComTypeDescriptor.cs index 8feb2c7..6278c29 100644 --- a/src/thirtytwo/Win32/System/Com/ComTypeDescriptor.cs +++ b/src/thirtytwo/Win32/System/Com/ComTypeDescriptor.cs @@ -93,7 +93,7 @@ public ComTypeDescriptor(IComPointer comObject) PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties() { InitializePropertyDescriptors(); - return new(_properties.ToArray()); + return new([.. _properties]); } PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[]? attributes) => throw new NotImplementedException(); diff --git a/src/thirtytwo/Win32/System/Com/EnumUnknown.cs b/src/thirtytwo/Win32/System/Com/EnumUnknown.cs index ff0d30c..0e0f498 100644 --- a/src/thirtytwo/Win32/System/Com/EnumUnknown.cs +++ b/src/thirtytwo/Win32/System/Com/EnumUnknown.cs @@ -10,15 +10,8 @@ public unsafe abstract class EnumUnknown : IEnumUnknown.Interface, IManagedWrapp public EnumUnknown(int count, int index = 0) { - if (count < 0) - { - throw new ArgumentOutOfRangeException(nameof(count)); - } - - if (index < 0) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } + ArgumentOutOfRangeException.ThrowIfNegative(count); + ArgumentOutOfRangeException.ThrowIfNegative(index); _count = count; _index = index; diff --git a/src/thirtytwo/Win32/System/Com/IDispatch.cs b/src/thirtytwo/Win32/System/Com/IDispatch.cs index 1755ef3..742fa3c 100644 --- a/src/thirtytwo/Win32/System/Com/IDispatch.cs +++ b/src/thirtytwo/Win32/System/Com/IDispatch.cs @@ -14,7 +14,7 @@ public int[] GetIdsOfNames(params string[] names) if (names.Length == 0) { - return Array.Empty(); + return []; } using StringParameterArray namesArg = new(names); diff --git a/src/thirtytwo/Win32/System/Ole/EnumVARIANT.cs b/src/thirtytwo/Win32/System/Ole/EnumVARIANT.cs index 1aea3f9..763c979 100644 --- a/src/thirtytwo/Win32/System/Ole/EnumVARIANT.cs +++ b/src/thirtytwo/Win32/System/Ole/EnumVARIANT.cs @@ -13,15 +13,8 @@ public unsafe abstract class EnumVARIANT : IEnumVARIANT.Interface, IManagedWrapp public EnumVARIANT(int count, int index = 0) { - if (count < 0) - { - throw new ArgumentOutOfRangeException(nameof(count)); - } - - if (index < 0) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } + ArgumentOutOfRangeException.ThrowIfNegative(count); + ArgumentOutOfRangeException.ThrowIfNegative(index); _count = count; _index = index; diff --git a/src/thirtytwo/Win32/System/Variant/VARIANT_ToObject.cs b/src/thirtytwo/Win32/System/Variant/VARIANT_ToObject.cs index 3e99b9d..4ae1c3e 100644 --- a/src/thirtytwo/Win32/System/Variant/VARIANT_ToObject.cs +++ b/src/thirtytwo/Win32/System/Variant/VARIANT_ToObject.cs @@ -62,7 +62,7 @@ public unsafe partial struct VARIANT } } - private static object? ToArray(SAFEARRAY* psa, VARENUM vt) + private static Array? ToArray(SAFEARRAY* psa, VARENUM vt) { if (psa is null) { diff --git a/src/thirtytwo/WindowStyles.cs b/src/thirtytwo/WindowStyles.cs index 06e5584..90a30d4 100644 --- a/src/thirtytwo/WindowStyles.cs +++ b/src/thirtytwo/WindowStyles.cs @@ -143,6 +143,4 @@ public enum WindowStyles : uint /// Same as . /// ChildWindow = WINDOW_STYLE.WS_CHILDWINDOW -} - -#pragma warning restore CA1069 // Enums values should not be duplicated \ No newline at end of file +} \ No newline at end of file diff --git a/src/thirtytwo/thirtytwo.csproj b/src/thirtytwo/thirtytwo.csproj index 849b617..d8e229e 100644 --- a/src/thirtytwo/thirtytwo.csproj +++ b/src/thirtytwo/thirtytwo.csproj @@ -7,7 +7,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/thirtytwo_tests/ProcessAndThreads/ProcessInfoTests.cs b/src/thirtytwo_tests/ProcessAndThreads/ProcessInfoTests.cs index 8dba1f9..f3edf1b 100644 --- a/src/thirtytwo_tests/ProcessAndThreads/ProcessInfoTests.cs +++ b/src/thirtytwo_tests/ProcessAndThreads/ProcessInfoTests.cs @@ -22,11 +22,13 @@ public void BasicFunctionality() } } + /* private void CannotModify() { ProcessInfo info = new(); // This doesn't compile as it returns a ref readonly - // info[0].UniqueProcessId = default; + info[0].UniqueProcessId = default; } + */ }