Skip to content
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

Closed
mostmand opened this issue Oct 15, 2022 · 6 comments
Closed

Make classes sealed by default #28610

mostmand opened this issue Oct 15, 2022 · 6 comments
Assignees
Labels
untriaged Request triage from a team member

Comments

@mostmand
Copy link

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

@dotnet-issue-labeler
Copy link

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.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Request triage from a team member label Oct 15, 2022
@KalleOlaviNiemitalo
Copy link
Contributor

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.

@KalleOlaviNiemitalo
Copy link
Contributor

C# language change was shot down in dotnet/csharplang#6506 (comment).

@KalleOlaviNiemitalo
Copy link
Contributor

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/.

@martincostello
Copy link
Member

Looks like this analyzer landed in 7.0.101, which causes false positives for top-level programs.

See #29164 (comment).

@baronfel
Copy link
Member

Closing this as the language change was rejected and an analyzer is available for users that want it.

@baronfel baronfel closed this as not planned Won't fix, can't repro, duplicate, stale Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

4 participants