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

Add Create method for types MONITORINFO and MONITORINFOEX #371

Closed
psulek opened this issue Jan 27, 2023 · 2 comments
Closed

Add Create method for types MONITORINFO and MONITORINFOEX #371

psulek opened this issue Jan 27, 2023 · 2 comments

Comments

@psulek
Copy link
Contributor

psulek commented Jan 27, 2023

Is your feature request related to a problem? Please describe.
Type MONITORINFO and MONITORINFOEX both have field cbSize, which as described in docs must be set via sizeof() before calling method GetMonitorInfo() (both overloads).

This can be confusing for new users (especially new C#/dotnet coders) that calling var info = new MONITORINFO(); is not enough, and required construct is: var info = new MONITORINFO{ cbSize = sizeof(MONITORINFO) };

Also there can be (depends on user code context) error like: 'MONITORINFO' does not have a predefined size, therefore sizeof can only be used in an unsafe context.

Describe the additions or enhancements you'd like
Create static method Create() for both types MONITORINFO and MONITORINFOEX which will set cbSize automatically for user.

psulek pushed a commit to psulek/Vanara that referenced this issue Jan 27, 2023
@dahall
Copy link
Owner

dahall commented Jan 27, 2023

Thank you for submitting a PR. In many places in the project I have used the public static STRUCTNAME Default => new() { cbSize = (uint)Marshal.SizeOf(typeof(STRUCTNAME)) } pattern, rather than the Create method pattern. See here. For consistency, will you adapt your PR to use the library pattern and then I'll accept?

@psulek
Copy link
Contributor Author

psulek commented Jan 28, 2023

Sure, sounds good!

psulek pushed a commit to psulek/Vanara that referenced this issue Jan 28, 2023
dahall pushed a commit that referenced this issue Jan 29, 2023
* #371 Add Create method for types MONITORINFO and MONITORINFOEX

* fixed CodeFactor issues

* #371 Add Create method for types MONITORINFO and MONITORINFOEX

* fixed CodeFactor issues

* changed Create methods to Default property

* fixed MONITORINFOEX.Create() with MONITORINFOEX.Default

---------

Co-authored-by: Peter Šulek <peter.sulek@synotgames.com>
@dahall dahall closed this as completed Jan 29, 2023
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

No branches or pull requests

2 participants