Allow using static SomeClass to bring overloaded operators into scope. #2294
-
This proposal is to enable adding operators to existing 3rd party types, or having different implementations of the same operators (for example, separate sets for GPU/CPU computation). Proposal consists of two changes:
static class ListMath {
public static List operator+ (List a, List b)
=> new List(a.Count + b.Count).AddRange(a).AddRange(b);
}
using static ListMath;
var a = new List{ 1 };
var b = new List{ 2 };
var c = a + b;
public static List<T> operator+<T> (List<T> a, List<T> b) => new List(a.Count + b.Count).AddRange(a).AddRange(b); Resolution of these operators should follow resolution rules of extension methods. E.g. if either operand has matching native operator defined, use that, otherwise use this extension operator. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
related: dotnet/roslyn#11159, dotnet/roslyn#6136, dotnet/roslyn#5165, dotnet/roslyn#4945, dotnet/roslyn#5624 (afaik some of the referenced proposals would allow extension operators, which should be what you request) |
Beta Was this translation helpful? Give feedback.
-
@Unknown6656 that was moved to #192 |
Beta Was this translation helpful? Give feedback.
-
Ah thanks, I was unable to find it with a superficial search. |
Beta Was this translation helpful? Give feedback.
@Unknown6656 that was moved to #192