Alternative extensions syntax related to LDM October 14th, 2024 #8524
OJacot-Descombes
started this conversation in
LDM Notes
Replies: 2 comments 12 replies
-
Similar spaghetti at the wall, partial extensions that each can have a different target. If combined with flattening the generics (e.g. the extension generic type parameters are prepended to the extension members), that would also make them binary compatible with existing extension methods. public partial extension Enumerable for IEnumerable {
public IEnumerable<T> OfType<T>() { ... }
}
public partial extension Enumerable<T> for IEnumerable<T> {
public IEnumerable<T> Where(Func<T, bool> predicate) { ... }
}
public partial extension Enumerable<T> for IOrderedEnumerable<T> {
public IOrderedEnumerable<T> ThenBy<TKey>(Func<T, TKey> selector) { ... }
}
public partial static class Enumerable {
public static IEnumerable<T> Empty<T>() { ... }
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
This version of the syntax did come up during the meeting. It still has the problem of "where is the type parameter introduced", so we're not satisfied with it. |
Beta Was this translation helpful? Give feedback.
12 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What about overloaded extensions, i.e., extensions having the same name, but for different types?
Instead of the syntax proposed in the LDM for October 14th, 2024
we would have
And we could introduce the type parameter like this:
Beta Was this translation helpful? Give feedback.
All reactions