How to query if a type is a static class using reflection?

Hi! I am using attributes in classes, but I want to raise an error if the attribute was declared in a static class. There is no way to do this using AttributeUsage.

I have the type, but there are no methods in the Type class to query if a class was declared static. I found out that static classes are both abstract and sealed. I am using this code to figure this out,

bool IsClassStatic {

get {

return type.IsAbstract && type.IsSealed;

}

}

Is this assumption correct Can I create a non-static class that is both abstract and sealed



Answer this question

How to query if a type is a static class using reflection?

  • How to query if a type is a static class using reflection?