-1

Why does type inference not work in the following case when I call DoSomething?

    public class A { }
    public class B<T> { }
    public static class Extensions
    {
        public static void DoSomething<TWrapper, TInner>(this TWrapper thing)
        where TWrapper : B<TInner>
        {

        }

        public static void Test()
        {
            new B<A>().DoSomething();
        }
    }

It seems to me that in the Test method TWrapper has to be B<A>, so TInner has to be A. Why can't the compiler figure this out?

John Tseng
  • 6,262
  • 2
  • 27
  • 35

1 Answers1

0

If you are trying to write extensions for B<T> then it would simply be:

public class A { }
public class B<T>{}
public static class Extensions
{
    public static void DoSomething<T>(this B<T> thing) {}
}

public static void Test()
{
    var test = new B<A>();

    test.DoSomething();
}
Cubicle.Jockey
  • 3,288
  • 1
  • 19
  • 31