-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Proposal: Infer generic type arguments from constructor arguments #2319
Comments
And it would be nice to extend this to #953 as well: ...
[DefaultValue(150)]
public int Id { get; set; }
...
public class DefaultValueAttribute<T> : Attribute
{
public DefaultValueAttribute(T @value) {}
} |
The one potential issue with this might be ambiguity. How do you feel about open generic type syntax, if only for cases where there could be ambiguity? var pair = new Pair<,>("string", 1); |
Maybe. |
It's also posible that there will be no more need in types like |
I believe this was a post stating that this feature was being seriously considered at some point. It may have been on the old codeplex site or it may have been in an early C# 6 possible feature list document, but I do not remember. @HaloFour Given the potential ambiguity, I would actually prefer that the full generic syntax new Pair<string, int>("string", 1) be required to disambiguate as opposed to the open generic syntax of new Pair<,>("string", 1) because I feel the former is clearer. |
I remember that when when C#6 preview was first introduced in @MadsTorgersen talk he said they will implement this feature: I think that this feature (#2319) and #1470 would be very nice improvement to C# type inference. I hope C# language team would discuss it on their language design meetings. I also would like to have all the other type inference improvements. |
We are now taking language feature discussion on https://github.com/dotnet/csharplang for C# specific issues, https://github.com/dotnet/vblang for VB-specific features, and https://github.com/dotnet/csharplang for features that affect both languages. We once considered doing this, but I think we are more likely to be interested in target-typed new expressions dotnet/csharplang#100 |
From code sample:
The text was updated successfully, but these errors were encountered: