I have the Carro
class that inherits from the Objeto
class and another CarroTeste
class that implements the abstract class TesteBase
which implements the ITeste
interface, both ( TesteBase
and ITeste
) typed with constraint to use only objects of class Objeto
, the problem occurs when I try to instantiate a CarroTeste
in an it% variable of ITeste<Objeto> teste = new CarroTeste();
, the IDE dis that I can not do an implicit type conversion.
Class code is down.
public class Objeto
{
protected string _nome;
public string nome { get{return _nome;} }
}
public class Carro : Objeto
{
public Carro()
{
_nome = "Carro";
}
}
public interface ITeste<T> where T : Objeto
{
string GetNome();
List<T> List { get; }
T GetChange(T obj);
}
public abstract class TesteBase<T> : ITeste<T> where T : Objeto
{
protected Objeto _obj = null;
public abstract string GetNome();
public abstract List<T> List { get; }
public abstract T GetChange(T obj);
}
public class CarroTeste : TesteBase<Carro>
{
public override string GetNome()
{
return "Meu nome é : " + _obj.nome;
}
public override List<Carro> List
{
get { return new List<Carro>(); }
}
public override Carro GetChange(Carro obj)
{
return obj;
}
}