-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Analyzer to flag a non-public class if it is not marked as sealed #23426
Comments
Only relevant if it has |
Why? In my experience, sealed types generally have better Further, we could use an option to produce warning if (public) types are not explicitly marked as non-sealed (with an attribute). |
Basically you are saying classes should always be sealed by default? Non-sealed classes are very useful to side-car data which you can't do with composition; e.g. pass type to api, which then api passes elsewhere to get the data back out - without creating a global(ish) dictionary on with the object as key.
If you are using |
This is what I'm trying to say: private class HasNoDerivedTypes {} // warning: the type can be sealed
public class HasNoDerivedTypes {} // optional warning
[NonSealed] public class HasNoDerivedTypes {} // explicit suppression Note: this is an IDE request. |
I see. It sounds like you want a suggestion that says to mark a class as sealed iff:
If so, that seems reasonable. Sounds like it would go in the roslyn-analyzers repo though. Note: afaict, there is no way to do this with the current analyzer system. You'd need a CompilationEndAction so you could ensure that there were no subclasses. But CompilationEndActions do not run by defualt for users. Tagging @heejaechang |
Tagging @mavasani , @dotnet/roslyn-analysis |
Duplicate of dotnet/runtime#49944 This analyzer will be implemented in dotnet/roslyn-analyzers repository, except for the "optional warning" part for public APIs. This is very unlikely to be useful. @jinujoseph I believe this issue can be closed. |
No description provided.
The text was updated successfully, but these errors were encountered: