Type inference in extension methods...
Mark Nicholls <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.advanced |
|---|---|
| Message-ID | <LISTSERV%[email protected]> |
I seem to be having problems with Type infence.
Here's an example...
interface IFoo
{
}
interface IBar<T>
{
}
class Foo : IFoo
{
}
class Bar : IBar<Foo>
{
}
static class Extensions
{
public static void Boom<X, Y>(this X x)
where X : Bar, IBar<Y>
where Y : Foo, new()
{
}
}
this line succeeds...
bar.Boom<Bar, Foo>();
and this line fails with 'Bar' does not contain a definition for 'Boom' and no extension method 'Boom' accepting a first argument of type 'Bar' could be found bla bla bla
bar.Boom();
with this extension method...
public static void Boom1<X>(this X x)
where X : Bar
{
}
this works
bar.Boom1();
...so the problem at least naively would seem to be that it has problems infering Y...rather than X...yet it's pretty obvious that if we try to substitute Bar as X in Boom...that Y must equally obviously have to be Foo
Any ideas?
....
===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives