Implement Every Interface #2801
Replies: 11 comments
-
I don't know what this is asking for. |
Beta Was this translation helpful? Give feedback.
-
I think he wants a non-generic type to be enumerable as any type ._. I can't fathom as to why though. |
Beta Was this translation helpful? Give feedback.
-
Looks like Extension everithing or shapes to me |
Beta Was this translation helpful? Give feedback.
-
Ah, got it. I'm not sure what this means at all either. :) |
Beta Was this translation helpful? Give feedback.
-
If I'm interpreting this correctly... Currently a generic interface requires the implementing class either be generic itself ( What you're suggesting is that a non-generic class can implement a generic interface for any So in your example, I could cast Is that correct? |
Beta Was this translation helpful? Give feedback.
-
@yaakov-h Yes! That is correct! |
Beta Was this translation helpful? Give feedback.
-
could you do it like so: class WhateverFactory
{
public static IEnumerable<T> Make<T>() => new Whatever<T>();
private class Whatever<T> : IEnumerable<T> { ... your impl ... }
} Also, @TonyValenti can you explain the use case where you want this? The request is too isolated from a real use case, so i don't know why you'd want this. |
Beta Was this translation helpful? Give feedback.
-
So how would that actually work? How will you actually provide the stream of integers if someone casts to Honestly curious here. Could you show what your implementation of |
Beta Was this translation helpful? Give feedback.
-
Arguably, this could be useful when dealing with numeric collections, which can be converted rather easily in between types (int to double to uint to string to etc). |
Beta Was this translation helpful? Give feedback.
-
@mcosmin222 That sounds more like #110 #1711 or #2038 . A completely unconstrained setup would not lend well to assuming its a numeric type. |
Beta Was this translation helpful? Give feedback.
-
Obviously op did not clearly state their purposes, but imo this is what they want. It is obviously reasonable to only do the cast between types which are convertible - maybe by overriding the explicit conversion operator. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
It would be nice if I could do the following:
With something like this, GetEnumerator would be implemented for every T.
Beta Was this translation helpful? Give feedback.
All reactions