In C #, I have a "secure" API code related to raising UAC. It includes getting the size of the listing (as follows)
int myEnumSize = sizeof (MyEnum);
The code itself is valid, compiles, works correctly, etc. But Resharper mistakenly designates it as an error ("It is impossible to use an unsafe construct in a safe context") inside the solution. ( Starting with version C # 2.0, applying sizeof to built-in types no longer requires unsafe mode. ) I like Resharper and I like analyzing solutions, but with this code in the solution I have a big red dot in the corner that always forces me to think that something is broken. If I tell resharper to ignore this error, it returns in a few minutes.
I would raise a problem with JetBrains, but I looked at their tracker and they already have one magazine that has been ignored since March. Looking further, they have at least two other cases when this journal was registered several years ago, both were dismissed with the status of โno repetitionโ. I donโt want to subscribe to their tracker just to vote for this mistake. I can still hold my breath for many years. The fastest way forward is simply to solve this problem.
What is the best alternative that is still the right one and the least likely to cause problems on the part of the maintainer?
I could write it hard:
int myEnumSize = 4;
Is there a better solution? - which does not use sizeof (enum)?
Btw:
Marshal.SizeOf()
completely "safe", but returns the wrong size.
PS. The code in questions is heavily dependent on Microsoft's UACSelfElvation demo code. If you want more information. But I do not think they are relevant.
c # sizeof interop resharper
DanO Nov 18 '10 at 20:44 2010-11-18 20:44
source share