Generic Chain Inference #8767
Unanswered
MrHPotter
asked this question in
Language Ideas
Replies: 3 comments 1 reply
-
I think that falls under: #8712 |
Beta Was this translation helpful? Give feedback.
0 replies
-
If your method public IConsumerRegistry RegisterConsumer<TConsumer, TEvent>(TConsumer consumer)
where TConsumer : IConsumer<TEvent>
where TEvent: IEvent; Then this falls under proposal #997 (inference from constraints). |
Beta Was this translation helpful? Give feedback.
1 reply
-
#997 seems like it matches my wishes. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So i have often ran into the following Problem. Let's say i have a generic Consumer interface/class for consuming Events, now i want to Accept this into some kind of method. To have a very simple Example, say, we want to build out a Dictionary of EventType - Consumer Type, to call the appropriate Consumer. (I know we'd probably want do this via DI, but stick with me please)
Lets say we have a IConsumerRegistry interface exposing this Method. Right now this would look like
in this example it's decently harmless, but when trying to do interesting things with generics, this quickly gets out of hand.
My Idea would be, that we could partially Infer the TEvent Type Parameter of the Method here. then it would look like the following:
I think it could clean up Generic Definitions a lot, if we could Declare some of them only in the where Clauses, when another Type Parameter already depends on the Type.
Propagating Generic Types might no longer as quickly become a Readability Issue, if we do not have to include all of them in the <> Brackets when Calling or Declaring a Method.
So to recap:
I'd like to be able to define Generic Paramters in the Where clause only, if they are a Type Parameter to another Type Parameter, already defined for the Generic Declaration.
Beta Was this translation helpful? Give feedback.
All reactions