diff --git a/.editorconfig b/.editorconfig index c577452..15bd0b8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -62,7 +62,7 @@ dotnet_style_null_propagation = true:suggestion dotnet_style_explicit_tuple_names = true:suggestion # Whitespace options -dotnet_style_allow_multiple_blank_lines_experimental = false +dotnet_style_allow_multiple_blank_lines_experimental = false:silent # Non-private static fields are PascalCase dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.severity = suggestion @@ -189,6 +189,10 @@ dotnet_style_namespace_match_folder = true:suggestion dotnet_style_operator_placement_when_wrapping = beginning_of_line tab_width = 4 end_of_line = crlf +dotnet_style_readonly_field = true:suggestion +dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent +dotnet_style_allow_statement_immediately_after_block_experimental = true:silent +dotnet_code_quality_unused_parameters = all:suggestion # CSharp code style settings: [*.cs] @@ -210,11 +214,11 @@ csharp_indent_switch_labels = true csharp_indent_labels = flush_left # Whitespace options -csharp_style_allow_embedded_statements_on_same_line_experimental = false -csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false -csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false -csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = false -csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = false +csharp_style_allow_embedded_statements_on_same_line_experimental = false:silent +csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false:silent +csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false:silent +csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = false:silent +csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = false:silent # Prefer "var" everywhere csharp_style_var_for_built_in_types = true:suggestion @@ -286,6 +290,12 @@ csharp_style_prefer_range_operator = true:suggestion csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion csharp_style_prefer_tuple_swap = true:suggestion csharp_style_prefer_utf8_string_literals = true:suggestion +csharp_style_unused_value_expression_statement_preference = discard_variable:silent +csharp_style_unused_value_assignment_preference = discard_variable:suggestion +csharp_style_deconstructed_variable_declaration = true:suggestion +csharp_style_prefer_readonly_struct = true:suggestion +csharp_prefer_static_local_function = true:suggestion +csharp_style_prefer_readonly_struct_member = true:suggestion [src/{Compilers,ExpressionEvaluator,Scripting}/**Test**/*.{cs,vb}] diff --git a/OotD.Core/OotD.Core.csproj b/OotD.Core/OotD.Core.csproj index 89207c9..b415023 100644 --- a/OotD.Core/OotD.Core.csproj +++ b/OotD.Core/OotD.Core.csproj @@ -31,6 +31,7 @@ true True 7.0 + true true diff --git a/OotD.Core/Utility/UnsafeNativeMethods.cs b/OotD.Core/Utility/UnsafeNativeMethods.cs index bbb5efb..06c2437 100644 --- a/OotD.Core/Utility/UnsafeNativeMethods.cs +++ b/OotD.Core/Utility/UnsafeNativeMethods.cs @@ -20,7 +20,7 @@ namespace OotD.Utility; -internal static class UnsafeNativeMethods +internal static partial class UnsafeNativeMethods { private static readonly nint HWND_BOTTOM = new(1); private static readonly nint HWND_TOPMOST = new(-1); @@ -53,19 +53,20 @@ internal struct WINDOWPOS internal int flags; } - [DllImport("dwmapi.dll", PreserveSig = false)] - private static extern void DwmSetWindowAttribute(nint hwnd, int attr, ref int attrValue, int attrSize); + [LibraryImport("dwmapi.dll")] + private static partial int DwmSetWindowAttribute(nint hwnd, int attr, ref int attrValue, int attrSize); - [DllImport("user32.dll")] - internal static extern bool ReleaseCapture(); + [LibraryImport("user32.dll", EntryPoint = "ReleaseCapture")] + [return: MarshalAs(UnmanagedType.Bool)] + internal static partial bool ReleaseCapture(); - [DllImport("user32.dll")] - internal static extern nint SendMessage(nint hWnd, uint Msg, nint wParam, nint lParam); + [LibraryImport("user32.dll", EntryPoint = "SendMessageA")] + internal static partial nint SendMessage(nint hWnd, uint Msg, nint wParam, nint lParam); - [DllImport("user32.dll")] - private static extern bool SetWindowPos( - nint hWnd, - nint hWndInsertAfter, + [LibraryImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + private static partial void SetWindowPos(IntPtr hWnd, + IntPtr hWndInsertAfter, int X, int Y, int cx, @@ -95,24 +96,24 @@ internal static void SendWindowToTop(Form windowToSendToTop, [CallerMemberName] SetWindowPos(windowToSendToTop.Handle, HWND_TOPMOST, 0, 0, 0, 0, ZPOS_FLAGS); } - [DllImport("user32.dll", SetLastError = true)] - private static extern int GetWindowLong(IntPtr hWnd, int nIndex); + [LibraryImport("user32.dll", SetLastError = true)] + private static partial int GetWindowLong(IntPtr hWnd, int nIndex); - [DllImport("user32.dll")] + [LibraryImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] - private static extern bool IsWindowVisible(IntPtr hWnd); + private static partial bool IsWindowVisible(IntPtr hWnd); - [DllImport("user32.dll")] - private static extern IntPtr GetShellWindow(); + [LibraryImport("user32.dll")] + private static partial IntPtr GetShellWindow(); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] private static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount); - [DllImport("user32.dll", SetLastError = true)] - private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); + [LibraryImport("user32.dll", SetLastError = true)] + private static partial uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); - [DllImport("user32.dll")] - private static extern IntPtr GetWindow(IntPtr hWnd, uint wCmd); + [LibraryImport("user32.dll")] + private static partial IntPtr GetWindow(IntPtr hWnd, uint wCmd); /// /// Does not hide the calendar when the user hovers their mouse over the "Show Desktop" button @@ -122,8 +123,8 @@ internal static void SendWindowToTop(Form windowToSendToTop, [CallerMemberName] internal static void RemoveWindowFromAeroPeek(IWin32Window window) { var renderPolicy = (int)DwmNCRenderingPolicy.Enabled; - - DwmSetWindowAttribute(window.Handle, DWMWA_EXCLUDED_FROM_PEEK, ref renderPolicy, sizeof(int)); + Marshal.ThrowExceptionForHR( + DwmSetWindowAttribute(window.Handle, DWMWA_EXCLUDED_FROM_PEEK, ref renderPolicy, sizeof(int))); } private enum DwmNCRenderingPolicy diff --git a/OotD.x64/OotD.x64.csproj b/OotD.x64/OotD.x64.csproj index d5331fe..81d954d 100644 --- a/OotD.x64/OotD.x64.csproj +++ b/OotD.x64/OotD.x64.csproj @@ -26,6 +26,7 @@ true True 7.0 + true true diff --git a/OotD.x86/OotD.x86.csproj b/OotD.x86/OotD.x86.csproj index ad75a26..0b51f0d 100644 --- a/OotD.x86/OotD.x86.csproj +++ b/OotD.x86/OotD.x86.csproj @@ -26,6 +26,7 @@ true True 7.0 + true true