C# 如何在泛型构造函数中获取类名

C# 如何在泛型构造函数中获取类名,c#,generics,reflection,C#,Generics,Reflection,有没有办法在contstructor中获取类名,以便以后可以将其用于多个方法 这显然不起作用,但有什么方法可以做到这一点……或者我只需要在构造函数中实例化该类的一个新实例,然后执行\u className=classInstance.GetType().Name public class Repository<TEntity> : IRepository<TEntity> where TEntity : class, Domain.IEntity, new() {

有没有办法在contstructor中获取类名,以便以后可以将其用于多个方法

这显然不起作用,但有什么方法可以做到这一点……或者我只需要在构造函数中实例化该类的一个新实例,然后执行
\u className=classInstance.GetType().Name

public class Repository<TEntity> : IRepository<TEntity>
    where TEntity : class, Domain.IEntity, new()
{
    private APIContext _apiContext;
    private string _className;

    public Repository(APIContext apiContext)
    {
        _apiContext = apiContext;
        _className = TEntity.GetType().Name; <---- any way to do this?
    }

    public async Task<TEntity> GetByIdAsync(int id)
    {

        string strPath = string.Format("/{0}s/v1/{1}", _className, id); <----**used here**

        string jsonStringResponse = await RestAPIHelper.Get(_apiContext, strPath);
        TEntity entity = JsonConvert.DeserializeObject<TEntity>(jsonStringResponse);
        return entity;
    }
}
公共类存储库:IRepository
其中tenty:class,Domain.ienty,new()
{
私有APIContext_APIContext;
私有字符串_className;
公共存储库(APIContext APIContext)
{
_apiContext=apiContext;
_className=tenty.GetType().Name;应该是

_className = typeof(TEntity).Name; 
typeof(TEntity).名称
?的可能副本