Replies: 11 comments
-
First use case would also benefit from #186 to avoid unnecessary copying. |
Beta Was this translation helpful? Give feedback.
-
I'm not sure your
|
Beta Was this translation helpful? Give feedback.
-
@svick You are right, I've updated the use case so that it works without problems |
Beta Was this translation helpful? Give feedback.
-
@alrz's use case from dotnet/roslyn#16159: static IEnumerable<(T, U)> GetEnumerator<T, U>(
this (IEnumerable<T> xs, IEnumerable<U> ys) source)
=> source.xs.Zip(source.ys, (x, y) => (x, y));
foreach(var (x, y) in (new int[1], new byte[2])) { } |
Beta Was this translation helpful? Give feedback.
-
I would champion this. Effectively, this is saying "use the pattern based approach for 'foreach' that we use in other places, like Deconstruct, Linq, etc." 'foreach' is already pattern based in that it doesn't expect you to have to actually implement IEnumerable or IEnumerator. But it wasn't extended enough to support extensions. It would be nice to just make this possible. |
Beta Was this translation helpful? Give feedback.
-
This would be wonderful since, currently, certain things are only possible to write with extension methods. The primary example of this is methods available only to specific generic instantiations, such as the tuple example (where |
Beta Was this translation helpful? Give feedback.
-
@Richiban Even though I think |
Beta Was this translation helpful? Give feedback.
-
Is this issue dead? With the introduction of |
Beta Was this translation helpful? Give feedback.
-
I'm willing to champion this. I'll work on writing up a more complete spec. |
Beta Was this translation helpful? Give feedback.
-
I've submitted #3194 as a formal proposal for this. |
Beta Was this translation helpful? Give feedback.
-
Cleaning up the discussion: this is still championed in #3194. We just shouldn't have 2 things in the language version planning areas. |
Beta Was this translation helpful? Give feedback.
-
In C#, for foreach loop to work on type it requires public
GetEnumerator
method. I propose to relax this requirement to allow extension methods to implementGetEnumerator
. This would be especially usefull for generic types, where you can define extension method only for subset of the type parameters.Use cases:
Beta Was this translation helpful? Give feedback.
All reactions