Possible Duplicate:
Determine if a type is static
Duplicate of Determine if a type is static
Is there a property/attribute I can inspect to see if a System.Type
is a static class?
I can do this indirectly, by testing that the Type
has static methods, and no instance methods beyond those inherited from System.Object
, however it doesn't feel clean (I've a sneaking suspicion I'm missing something and this isn't a rigorous enough definition of static class
).
Is there something I'm missing on the type that will categorically tell me this is a static class?
Or is static class
c# syntax sugar and there's no way to express it in IL?
Thanks
BW
yea, you need to test for both IsAbstract
and IsSealed
. A non static class can never be both. Not fantastic but it works.
At IL level any static class is abstract and sealed. So you can do something like this:
Type myType = typeof(Form1);
if (myType.GetConstructor(Type.EmptyTypes) == null && myType.IsAbstract && myType.IsSealed)
{
// class is static
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With