Consulting type passed via generic method

Asked

Viewed 65 times

1

I have the following situation:

public List<TEntidade> MeuMetodo<TEntidade>()
{
      //My Code Here
}

Is there any way I can catch this guy from Tentity? The ultimate goal is to use this Type to create a switch...

2 answers

1


Use the typeof. Then, just get the string with the name, and apply on the switch, thus:

Type tipoEntidade = typeof(TEntidade);

string tipo = tipoEntidade.FullName;

switch (tipo)
{
    ...
}

0

You can use Typeof() thus:

Type seuTipo = typeof(TEntidade);

Browser other questions tagged

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