Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic operators support in C#. #7599

Closed
dmitriyse opened this issue Dec 18, 2015 · 6 comments
Closed

Generic operators support in C#. #7599

dmitriyse opened this issue Dec 18, 2015 · 6 comments

Comments

@dmitriyse
Copy link

Currently c# does not support generic operators definition like that:

public static MyAddExpression<SomeClass, T> operator<T>+(SomeClass c, T t){return ...}

This support can be usefull to build advanced libs with expressions (validation expressions in my case).

This is only C# limitation, CLR ready for this feature.
We can already define operator in different syntax.

[SpecialName]
public  static string op_Addition(SomeClass c, string s){...}

No changes in CLR needed to define generic operator in this syntax:

[SpecialName]
public static MyAddExpression<SomeClass, T> op_Addition<T>(SomeClass c, T t){return ...}

but later C# does not recognize it.

Please add this proposal to the C# 7.0 wish list.

@tpetrina
Copy link

I would love this feature. Non-generic operators are limiting.

@dsaf
Copy link

dsaf commented Dec 20, 2015

Related to #3391 and #2147.

@msedi
Copy link

msedi commented Mar 19, 2016

Yes. In my opinion this is now absolutely necessary. Having only generics that are not fully equivalent to C++ generics (in functional behaviour) are absolutely mandatory. I guess there are many guys out there requesting this feature. Instead a lot of people here are complaining about syntactic sugar.

@orthoxerox
Copy link
Contributor

Might help solve the problem of verbose generic patterns discussed in #10153. If is was generic the pattern could infer its generic type.

@grwGeo
Copy link

grwGeo commented Jul 22, 2016

I have needed this feature trying to model mathematical entities and it is a definite must. It will save tons of repetitive code and make the conceptual model richer. Also type inference would do wonders in this scenario.

@gafter
Copy link
Member

gafter commented Aug 11, 2017

Issue moved to dotnet/csharplang #813 via ZenHub

@gafter gafter closed this as completed Aug 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants