Generics Challage: Assert Return Types Matches
I feel that I gave it too much already, and I am giving up. A workaround is too good for this issue.
Given the following class defination:
public class Dog
{
public static MethodInfo LastCall = null;
public class BarkInvocation<T>
{
public T Bark()
{
LastCall = (MethodInfo)MethodInfo.GetCurrentMethod();
return default(T);
}
}
public T Bark<T>()
{
return new BarkInvocation<T>().Bark();
}
}
Can you make this print true?
public class Program
{
[STAThread]
static void Main(string[] args)
{
Dog d = new Dog();
d.Bark<IList<string>>();
Type returnType = Dog.LastCall.ReturnType;
List<string> strings = new List<string>();
Console.WriteLine(returnType.IsInstanceOfType(strings));
}
}

Comments
Comment preview