Proposal: overriding generic properties #1436
Replies: 12 comments
-
What is the use case for this pattern? And since you can already do this and you're just asking for more succinct syntax, are you sure the use cases for this are sufficiently popular? Also, I don't think the proposed syntax is possible: |
Beta Was this translation helpful? Give feedback.
-
This doesn't make sense, because You can already achieve the useful behaviour by using more generic types (e.g. |
Beta Was this translation helpful? Give feedback.
-
The idea is to avoid having to declare a new generic class like the one you suggest (I've been already there). It could make sense if you think it as overriding covariant reference types. |
Beta Was this translation helpful? Give feedback.
-
I'm a game developer, and I'd use it everywhere -where applicable, when an abstract class with one ore more generic-parameters is declared, and you need to extend a specification (derived class) of such class overriding, for instance, covariant return reference types and properties (services, behaviours, etc.). So no, I don't think it would be popular enough in the C# community as a whole. But I lose nothing for proposing it. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Indeed. |
Beta Was this translation helpful? Give feedback.
-
The title makes me think of @CyrusNajmabadi's “for all intensive porpoises.” 😄 |
Beta Was this translation helpful? Give feedback.
-
I've edited the first post because I forgot to add the 'override' keyword. |
Beta Was this translation helpful? Give feedback.
-
This is close to what existential types or associated types can do (known in Scala as abstract types). I think those are a better way of achieving the "non-generic on the outside, generic on the inside" effect. Beta called it "virtual types", and simply allowed nested types to be overwritten with more derived ones, just like other members. |
Beta Was this translation helpful? Give feedback.
-
Understood. As a workaround I'm partially getting the desired result by defining generic interfaces with covariant parameters and generic delegates with contravariant ones (that are then used in the former to declare events). |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Wow! Nice to see Covariant Returns is part of C# 9, which follows the spirit of this proposal. Thanks @MadsTorgersen! |
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.
-
Consider the following scenario:
Once you specify the generic type on a class with a non-abstract parameter, you cap the level of depth on the class hierarchy from that point and on. For the example above that would apply from MyDerivedClass1 and on ...
So my question: could it be feasible to override such limitation for cases where the new type inherits from the previous type? Like, for that example:
Picture it not for that specific example but also in general:
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions