Simplified generic extended method? #2645
Replies: 9 comments
-
Does this have anything to do with extension methods? Surely it applies to methods generally? |
Beta Was this translation helpful? Give feedback.
-
@canton7 - not the OP, but I have noticed that generics in extension methods can be more of a pain. For instance, an instance method in a generic class, versus an extension method of the same class:
To call these methods, because the compiler can't certain what type
Having to include |
Beta Was this translation helpful? Give feedback.
-
@spydacarnage Yes. Thank you. I've put up with this for a long time. @canton7 I think this is faster than waiting for some of the features of AOP. And it will bring more convenience. I shouldn't say too much off the subject. I just think generics need to be evolved. If possible, perhaps this requires an investigation. |
Beta Was this translation helpful? Give feedback.
-
I think this somewhat falls under this proposal: |
Beta Was this translation helpful? Give feedback.
-
@HaloFour - so, would you expect, under #92, that the following (based on my previous code) would compile correctly?
Because if so, that alleviates 99% of my problem, assuming the level of type inference will extend upwards sometimes? For instance:
|
Beta Was this translation helpful? Give feedback.
-
I think so, yes. I don't spell it out in such specific terms but effectively if the method has a generic type parameter that is used only for the return type of the method and the result of that method is used in an assignment then the compiler would use the type of that assignment to infer the generic type parameter. The type to which the result is assigned would have to be unambiguous, though. |
Beta Was this translation helpful? Give feedback.
-
@HaloFour |
Beta Was this translation helpful? Give feedback.
-
Does anyone label this Issue? |
Beta Was this translation helpful? Give feedback.
-
@canton7 @spydacarnage @HaloFour I have fix the case code above. Do I need to go to Roslyn or Coreclr to mention something like this Issue? |
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.
-
Case 1:
Case 2:
Beta Was this translation helpful? Give feedback.
All reactions