-
The docs currently recommend that a Here's my question: Why isn't it better for a non-sealed base class to declare only If the base class has only Here's the only problem I was able to think of so far. Let's say we get the idea that we want to change the base class by introducing a finalizer, perhaps after shipping the class as public API. Adding a finalizer means adding a I'm not aware of all the factors yet, but if the only thing you lose is the ability for the base class to gain a finalizer later on, wouldn't you expect the docs to recommend losing this ability? I thought for sure I'd see the docs recommending |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
CC. @stephentoub, @bartonjs |
Beta Was this translation helpful? Give feedback.
-
The biggest reason is consistency... so that there's not one pattern for types that were declared in 2020 and another for older types. We had a big discussion about this last winter and that was our basic conclusion: we've had a pattern for 15+ years, and it's too disruptive to change it (and the pattern isn't very expensive). In addition to having a place where the finalizer could be inserted (though the new Framework Design Guidelines says not to make public types finalizable (but remember: not all types derived from public types are public)), it makes it much clearer when a type /does/ introduce a finalizer where the SuppressFinalize goes: the place that originally declared it was IDisposable, in the non-virtual Dispose method. |
Beta Was this translation helpful? Give feedback.
-
Previous discussion on this topic: dotnet/docs#5485. |
Beta Was this translation helpful? Give feedback.
The biggest reason is consistency... so that there's not one pattern for types that were declared in 2020 and another for older types.
We had a big discussion about this last winter and that was our basic conclusion: we've had a pattern for 15+ years, and it's too disruptive to change it (and the pattern isn't very expensive).
In addition to having a place where the finalizer could be inserted (though the new Framework Design Guidelines says not to make public types finalizable (but remember: not all types derived from public types are public)), it makes it much clearer when a type /does/ introduce a finalizer where the SuppressFinalize goes: the place that originally declared it was IDis…