PROPOSAL: Constraint Inheritance / Inference #8304
Labels
Area-Language Design
Discussion
Resolution-Duplicate
The described behavior is tracked in another issue
Today in C#, constraints on methods get automatically "inherited" by derived classes and do not need to be redefined. This is a good thing and helps keep my code clean, concise, and readable, and when you need to refactor a base method, you only have to refactor the base method.
That is all goodwhen you're working with generic methods, but when you're working with Generic classes, you have a different story. Here is an example:
Today, with a class definition like this, if I refactor
BaseClass<T>
and add a new constraint onto<T>
, I then have to go find every derived class that extend'sBaseClass<T>
and copy/paste that new constraint intoDerivedClass<T>
's definition. This has a couple of problems:DerivedClass<T>
with redefinitions of base class stuff.In the example above,
DerivedClass's <T>
should automatically "inherit" the constraints that are placed on it byBaseClass<T>
.In order to simplify things and preserve compatibility with existing code, using the
where
clause in a derived class should specify additional constraints that may or may not already be inferred from its usage.The text was updated successfully, but these errors were encountered: