2
I made the following code:
using System;
public class Program
{
    public static void Main()
    {
        //Este método funciona
        Metodo(new ClasseTeste(){ Obj = new Registro(){ Nome = "Nome Teste"}});
        //Este não
        Metodo2(new ClasseTeste(){ Obj = new Registro(){ Nome = "Nome Teste2"}});
        //Este não          
        Metodo3(new ClasseTeste(){ Obj = new Registro(){ Nome = "Nome Teste3"}});
    }
    public static void Metodo<T>(IBase<T> parametro) where T: class,IRegistro
    {
        string nome = parametro.Obj.Nome;
        Console.WriteLine(nome);
    }
    public static void Metodo2(IBase<IRegistro> parametro)
    {
        string nome = parametro.Obj.Nome;
        Console.WriteLine(nome);
    }
    public static void Metodo3(Teste<IRegistro> parametro)
    {
        string nome = parametro.Obj.Nome;
        Console.WriteLine(nome);
    }
}
Registering:
public interface IRegistro
{
    string Nome {get;set;}
}
public class Registro : IRegistro
{
    public string Nome {get;set;}
}
Generic interface and implementation:
public interface IBase<T> where T : class
{
    T Obj {get;set;}
}
public abstract class Teste<T> : IBase<T> where T : class, IRegistro
{
    public T Obj {get;set;}
}
public class ClasseTeste : Teste<Registro>
{
}
The First Method Metodo works, the other two don’t.
The following error is returned:
Cannot convert ClasseTeste to IBase<IRegistro>
Question:
Because I cannot convert an object that implements the interface into its own interface ?
I put in the Dotnetfiddle
Edit:
After reading about Variance in generic interfaces (C#)
I changed the code to a covariant interface:
using System;
public class Program
{
    public static void Main()
    {
        Metodo(new ClasseTeste(){ Obj = new Registro(){ Nome = "Teste 1"} });
        Metodo2(new ClasseTeste(){ Obj = new Registro(){ Nome = "Teste 2"} });
        //Metodo3(new ClasseTeste());
    }
    public static void Metodo<T>(IBase<T> parametro) where T: class,IRegistro
    {
        string nome = parametro.GetObj().Nome;
        Console.WriteLine(nome);
    }
    public static void Metodo2(IBase<IRegistro> parametro)
    {
        string nome = parametro.GetObj().Nome;
        Console.WriteLine(nome);
    }
    public static void Metodo3(Teste<IRegistro> parametro)
    {
        string nome = parametro.GetObj().Nome;
        Console.WriteLine(nome);
    }
}
public interface IRegistro
{
    string Nome {get;set;}
}
public class Registro : IRegistro
{
    public string Nome {get;set;}
}
public interface IBase<out T> where T : class, IRegistro
{
    //T Obj{get;set;} //Erro (O Parametro T precisa ser invariante. T é Covariante
    T GetObj ();
    //void MetodoX(T obj); //Erro (O Parametro T precisa ser invariante. T é Covariante
}
public abstract class Teste<T> : IBase<T> where T : class, IRegistro
{
    public T Obj {get;set;}
    public T GetObj ()
    {
        return this.Obj;
    }
}
public class ClasseTeste : Teste<Registro>
{
}
The Method that waits
IBase<IRegistro>now acceptClasseTeste, but on the interface I cannot declare properties or methods with generic type parameters.
"Então quando você diz que vai receber Registro mas passa um IRegistro nada garante que o objeto que é certamente um IRegistro seja um Registro"It wouldn’t be the other way aroundIRegistroand step oneRegistro. IfRegistroimplementsIRegistroshould not be guaranteed?!– Rovann Linhalis
I understood about the variance, I read on this material: https://docs.microsoft.comin-Generic-interfaces and changed the code so that it accepts the conversion of types with a covariant interface, but I cannot declare properties and methods that receive generic type parameters. (I edited the question)
– Rovann Linhalis
My intention was to have a class that was not generic, receiving a generic object as a parameter, but it was not possible. The definition of covariance that I was able to do didn’t meet me either. I ended up doing the generic class as well. Thank you for your attention =]
– Rovann Linhalis