Não é possível converter implicitamente o tipo derivado para seu tipo genérico base
Eu tenho as seguintes classes 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; }
}
Agora, eu tenho uma fábrica que retornará objetos derivados do ThingConsumer como:
public class MyThingConsumer : ThingConsumer<Thing>
{
}
Minha fábrica atualmente se parece com isso:
public static class ThingConsumerFactory<T> where T : IThing
{
public static ThingConsumer<T> GetThingConsumer(){
if (typeof(T) == typeof(Thing))
{
return new MyThingConsumer();
}
else
{
return null;
}
}
}
Estou ficando enganado com este erro:Error 1 Cannot implicitly convert type 'ConsoleApplication1.MyThingConsumer' to 'ConsoleApplication1.ThingConsumer<T>'
Alguém sabe como realizar o que estou tentando fazer aqui?
Obrigado!
Chris