dotnet / pinvoke

A library containing all P/Invoke code so you don't have to import it every time. Maintained and updated to support the latest Windows OS.
MIT License
2.12k stars 222 forks source link

User32: make MENUITEMINFO.Create() static #458

Closed x1unix closed 4 years ago

x1unix commented 4 years ago

Hello, currently MENUITEMINFO.Create() is instance method and if I need to create the struct with correct size, I need to do this:

MENUITEMINFO mii = new MENUITEMINFO();
MENUITEMINFO correctMii = mii.Create();

Currently, I don't see any advantage of non-static .Create() because it doesn't utilize original struct's state:

 public MENUITEMINFO Create()
            {
                return new MENUITEMINFO
                {
                    cbSize = Marshal.SizeOf(typeof(MENUITEMINFO))
                };
            }

I think that it will be more convenient to make this method static to avoid mii declaration (or provide alternative way to initialize the struct):

MENUITEMINFO mii = MENUITEMINFO.Create();
AArnott commented 4 years ago

Ya, that's a bug in the API.