Consider adding SizeOf property to all structs
rickbrew opened this issue · comments
May not be a good idea, but worth considering.
There's a bug hazard right now in that the 'helper' structs which are unions of the 32-bit and 64-bit variants have a SizeOf
property. You need to know / remember when to use T.SizeOf
vs. Unsafe.SizeOf<T>()
, and if you incorrectly use the latter then you can get into trouble. It is not something that stands out as incorrect while doing a code review.
One possible solution is to put SizeOf
on all structs and have it be the de facto way of determining the struct's size.
I don't think that's an approach that I'd be happy with. For the most part, sizeof
and Unsafe.SizeOf<T>
is correct and its going to be the default/de-facto thing that people utilize.
It's only a handful of special types in um/ShellAPI
and um/SetupAPI
that differ here and so I think an analyzer is the right approach still. It helps flag some potentially unoptimal usage scenario and really only trips users up who need to both target 32-bit and use these exact types.
Having a different name for the helper wrappers is a different alternative; if there is some common name we can think of or separate namespace to put them under.
Sounds good. I figured you’d either agree, have an even better idea, or disagree with sound reasoning :)