C
C#2y ago
FusedQyou

❔ Check if Type is static

This question is probably vague as shit, but I always do this check to ensure a type is static:
private bool IsStatic(Type type)
{
return type.IsAbstract && type.IsSealed;
}
private bool IsStatic(Type type)
{
return type.IsAbstract && type.IsSealed;
}
So, this works because static classes are declared abstract and sealed at the IL level. My question is if this is actually valid and won't fail, ever. C# doesn't exactly have a isStatic field or something.
4 Replies
Thinker
Thinker2y ago
This should be fine (I think), because all static classses are "sealed abstract"
Denis
Denis2y ago
GitHub
ModularDoc/ClassDef.cs at 23c5d2daf99f539d77bf8d104df384b5e6bf075d ...
Modular documentation generator for .NET libraries. Currently supporting Markdown only for GitHub, GitLab, and Bitbucket - ModularDoc/ClassDef.cs at 23c5d2daf99f539d77bf8d104df384b5e6bf075d · hails...
Denis
Denis2y ago
Yes it is valid
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server