Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump up NuGet Packs and apply new Analyzer Rules. #12512

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

KlausLoeffelmann
Copy link
Member

@KlausLoeffelmann KlausLoeffelmann commented Nov 20, 2024

Updates the NuGet packages to the latest versions and applies the new respective Analyzer Rules.

Microsoft Reviewers: Open in CodeFlow

Copy link
Member

@JeremyKuhne JeremyKuhne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments. If many/most methods of a struct or class are unsafe we're leaning towards mark the whole type unsafe.

@@ -10,25 +10,25 @@ internal readonly partial struct WPARAM
public static unsafe implicit operator void*(WPARAM value) => (void*)value.Value;
public static unsafe implicit operator WPARAM(void* value) => new((nuint)value);

public static explicit operator HWND(WPARAM value) => (HWND)(nint)value.Value;
public static explicit operator WPARAM(HWND value) => new((nuint)value.Value);
public static unsafe explicit operator HWND(WPARAM value) => (HWND)(nint)value.Value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: at this point, should just make the struct itself unsafe

@@ -50,7 +50,7 @@ public unsafe CreateDcScope(
}

public static implicit operator HDC(in CreateDcScope scope) => scope.HDC;
public static implicit operator HGDIOBJ(in CreateDcScope scope) => (HGDIOBJ)(scope.HDC.Value);
public static unsafe implicit operator HGDIOBJ(in CreateDcScope scope) => (HGDIOBJ)(scope.HDC.Value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There really should be an implicit operator on HDC to convert to HGDIOBJ as that cast is always legit. Then this can just be scope.HDC.

@@ -30,7 +30,7 @@ public CreatePenScope(Color color, int width = 1) =>
HPEN = PInvokeCore.CreatePen(PEN_STYLE.PS_SOLID, width, color);

public static implicit operator HPEN(in CreatePenScope scope) => scope.HPEN;
public static implicit operator HGDIOBJ(in CreatePenScope scope) => (HGDIOBJ)scope.HPEN.Value;
public static unsafe implicit operator HGDIOBJ(in CreatePenScope scope) => (HGDIOBJ)scope.HPEN.Value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, should have an implicit conversion operator on HPEN to go to HGDIOBJ.

@@ -93,15 +93,15 @@
<PropertyGroup>
<CSharpIsNullAnalyzersVersion>0.1.495</CSharpIsNullAnalyzersVersion>
<DotNetAnalyzersDocumentationAnalyzersVersion>1.0.0-beta.59</DotNetAnalyzersDocumentationAnalyzersVersion>
<MicrosoftCodeAnalysisAnalyzersVersion>3.11.0-beta1.24219.2</MicrosoftCodeAnalysisAnalyzersVersion>
<MicrosoftCodeAnalysisCommonPackageVersion>4.10.0-3.final</MicrosoftCodeAnalysisCommonPackageVersion>
<MicrosoftCodeAnalysisAnalyzersVersion>3.12.0-beta1.24559.1</MicrosoftCodeAnalysisAnalyzersVersion>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want to update the versions for WPF as well. I'll sync with you on that.

@dotnet-policy-service dotnet-policy-service bot added 📭 waiting-author-feedback The team requires more information from the author and removed 📭 waiting-author-feedback The team requires more information from the author labels Nov 20, 2024
@@ -2318,8 +2318,7 @@ private unsafe void WndProc(ref Message message)

using Graphics graphics = paintScope.HDC.CreateGraphics();

IWin32Window? window = GetCurrentToolWindow();
if (window is not null)
if (GetCurrentToolWindow() is Control window)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this still be IWin32Window? Below code seems to indicate it may not always be a Control

Comment on lines +19 to +20
|| (OsVersion.IsWindows10_1607OrGreater()
&& (bool)PInvoke.AreDpiAwarenessContextsEqual(this, dpiContext));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit for readability:

Suggested change
|| (OsVersion.IsWindows10_1607OrGreater()
&& (bool)PInvoke.AreDpiAwarenessContextsEqual(this, dpiContext));
|| (OsVersion.IsWindows10_1607OrGreater()
&& (bool)PInvoke.AreDpiAwarenessContextsEqual(this, dpiContext));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants