Reference the class itself in the inheritance dynamically

Asked

Viewed 40 times

-1

Good morning,

i have the following code in c# Asp.net-Core:

public class AgentsTrans : BaseTrans<AgentsTrans> 

Basetrans is a generic base class that expects to receive a class as a parameter (Agentstrans).

In this case, it is working, but as there are many files and I would have to modify all one by one, I wonder if you know a way to pass this parameter in a generic way, making the base trans see the class you are inheriting without me having to refer tothere directly (as a this).

If anyone has a tip, it will be of great help.

In case you’re confused or don’t understand, I’ll try to clarify :)

  • Present the two classes, I do not understand why Agentstrans needs to inherit Basetrans and this depends on Agentstrans...

1 answer

-1

Hello. the question got confused more I believe I understood what you need.

The ideal would be you use interfaces, would be like this:

  public interface IBaseTransRepository<TEntity> : IDisposable where TEntity : class
    {
        Task Adicionar(TEntity entity);
        Task<TEntity> ObterPorId(Guid id);
        Task<TEntity> ObterPorId(int id);
        Task<List<TEntity>> ObterTodos();
        Task Atualizar(TEntity entity);
        Task Remover(Guid id);
        Task Remover(int id);
        Task<IEnumerable<TEntity>> Buscar(Expression<Func<TEntity, bool>> predicate);
        Task<int> SaveChanges();
    }


    public interface IAgentsTransRepository : IBaseTransRepository<AgentsTrans>
    {
        Task<AgentsTrans> ObterTodosOsAgentes(int IdUsuario);

    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.