sealed class analyzer #5631
Replies: 5 comments 19 replies
-
Why not just use an attribute? |
Beta Was this translation helpful? Give feedback.
-
I don't think this kind of juggling with modifiers is a good idea. |
Beta Was this translation helpful? Give feedback.
-
You might be interested in the discussion Stephen Toub started about shipping such an analyzer in the box with the SDK: dotnet/runtime#49944 |
Beta Was this translation helpful? Give feedback.
-
Closing out. As David mentions, this is trivially solvable with an analyzer. If there is a request for more extensive/configurable analyzers, that should go to dotnet/roslyn-analyzers. It's out of scope for the language (which likely won't be changing here).. |
Beta Was this translation helpful? Give feedback.
-
Is there any reason this cannot be a project setting like Then the compiler can make the class sealed if there are no virtual members declared. |
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.
-
I would like to propose the ability to explicitly mark a class as non-sealed. This is the default of course, but more often than not I want to seal my classes and there is currently no way for an analyzer to identify whether a class was intentionally left unsealed or not. To fix this, I would propose a new class modifier
virtual
to explicitly indicate that the developer intended for the class to be unsealed. This would then make it possible to write an analyzer that requires that a class be explicitlysealed
orvirtual
(or abstract, static, etc).My opinion is that
sealed
should have been the default for classes in C# (to match method behavior), and this would allow enforcing that opinion more easily in my own codebases.Beta Was this translation helpful? Give feedback.
All reactions