-
Notifications
You must be signed in to change notification settings - Fork 1.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
Make classes sealed by default #28610
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Apart from C# language changes: There is already an analyzer that shows which classes could be safely sealed. The project templates in .NET SDK could be changed to seal classes. |
C# language change was shot down in dotnet/csharplang#6506 (comment). |
The analyzer was added in dotnet/roslyn-analyzers#5594 to fix dotnet/runtime#49944. The code analysis warning CA1852 is not yet documented at https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/. |
Looks like this analyzer landed in 7.0.101, which causes false positives for top-level programs. See #29164 (comment). |
Closing this as the language change was rejected and an analyzer is available for users that want it. |
In C# each class in inheritable unless it is defined as sealed. Is it possible to make classes sealed as default unless defined as inheritable? Maybe a feature flag in csproj file to opt in could do the trick.
Additional context
Jon Skeet's response to a related question
Sealed classes are more performant than normal classes
The text was updated successfully, but these errors were encountered: