C
C#16mo 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
Thinker16mo ago
This should be fine (I think), because all static classses are "sealed abstract"
Denis
Denis16mo 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
Denis16mo ago
Yes it is valid
Accord
Accord16mo 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
More Posts
❔ How to limit while loop updates per second amountWhat i mean by the name is that: for a console application i'm developing (if you're wondering it's ❔ which of these queries is "better"? And will the second one work?I'm trying to get the total results of the query before pagination to display it to the client. But ❔ Two MS Graph Clients on same applicationWe all know you can DI graph into the application through `AddMicrosoftGraph`, but I'm trying to hav❔ ASP.NET Core Identity OTP creation dateSo, currently, I have an authentication server (not with IdentityServer4/Duende). I have enabled two✅ How to add variable instead of value in JSON dynamic array?```cs using Newtonsoft.Json; using System; public class ConsoleApp7 { public static void Main()✅ How to write special linq group by? How to shorten my code?I have function which named as `GetDepartmentsWithNested`. It returns `Task<Dictionary<string, strin❔ FluentValidation Custom Client Response?I have a FluentValidation implementation for my .net core API, currently when a validation exception✅ Mvvm toolkit - messenger not working? Recive messege not invokedHey there im trying to recieve a simple messege using messenger Got this code: ``` if (Re❔ Not able to mock a daprclient function in dotnetI am unit testing a function where I use the `InvokeMethodAsync` method of DaprClient but I constant❔ [Unity] Should I just move all my old scripts to another folder and start over?To make a long story short, I'm making a game and there's two gamemodes. The first gamemode turns ou