Closed
Description
Hi Roslyn Team:
When I was reading one of the feature requests from earlier:
#2212 (comment)
It made me think of something I have really been wanting as of late:
Pattern matching/better type inferencing with generics.
Today I can write code like this:
private static void Foo<T, X>(T Object) where T : IEnumerable<X>, IComparable<X> {
//Do Something
}
private class MyClass : IComparable<String>, IEnumerable<String> {
int IComparable<string>.CompareTo(string other) {
throw new NotImplementedException();
}
IEnumerator IEnumerable.GetEnumerator() {
throw new NotImplementedException();
}
IEnumerator<string> IEnumerable<string>.GetEnumerator() {
throw new NotImplementedException();
}
}
private static void CallMyFunction() {
var C = new MyClass();
Foo<MyClass, String>(C);
}
There is nastiness is in how I have to call the function.
private static void CallMyFunction() {
var C = new MyClass();
Foo<MyClass, String>(C);
}
In this example, I feel as though Foo should automatically figure out the type parameters and I should be able to call the method as follows:
private static void CallMyFunction() {
var C = new MyClass();
Foo(C);
}