No se puede convertir implícitamente el tipo derivado a su tipo genérico base
Tengo las siguientes clases e interfaces:
public interface IThing
{
string Name { get; }
}
public class Thing : IThing
{
public string Name { get; set; }
}
public abstract class ThingConsumer<T> where T : IThing
{
public string Name { get; set; }
}
Ahora, tengo una fábrica que devolverá objetos derivados de ThingConsumer como:
public class MyThingConsumer : ThingConsumer<Thing>
{
}
Mi fábrica actualmente se ve así:
public static class ThingConsumerFactory<T> where T : IThing
{
public static ThingConsumer<T> GetThingConsumer(){
if (typeof(T) == typeof(Thing))
{
return new MyThingConsumer();
}
else
{
return null;
}
}
}
Me estoy haciendo tropezar con este error:Error 1 Cannot implicitly convert type 'ConsoleApplication1.MyThingConsumer' to 'ConsoleApplication1.ThingConsumer<T>'
¿Alguien sabe cómo lograr lo que estoy intentando aquí?
¡Gracias!
Chris