Allow assemblies to have types default to sealed #6506
Replies: 3 comments 5 replies
-
|
this is very unlikely to happen. NRT was an extremely special case where the benefits were enormous, and the need for runtime compat with teh entire ecosystem was paramount. Because of htat, we allowed this special exception and added flags. For something like this, the best path forward would be to write an analyzer that errors on non-sealed classes unless it has a special attribute on it you define (e.g. |
Beta Was this translation helpful? Give feedback.
-
|
Consider the built-in CA1852 diagnostic for this that is shipping in the .NET 7 SDK: dotnet/runtime#49944 |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Proposing adding a new attribute to the csproj file e.g.
This change would alter the behavior of the compiler to implicitly mark classes as sealed if not otherwise marked, meaning they will not be allowed to be inherited and cannot have virtual members.
e.g.:
This would require a change to the allowed modifiers of types to allow the
virtualmodifier.Virtual members should be allowed in all virtual and abstract types the current behavior, but when Sealed=enabled, types without a modifier will not be allowed virtual members.
Beta Was this translation helpful? Give feedback.
All reactions