How can I get the type of generic parameter?
For example:
void Example<T>()
{
// Here I want to get the type of T (and how can I get if T is a primitive
// kind (int,bool,string) not class)
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That will get you the type object for type T.
type.IsPrimitivewill tell you if it’s one of the primitive types, see list here: http://msdn.microsoft.com/en-us/library/system.type.isprimitive.aspxAlso, note that although
stringis a basic type, which is very integrated with the .NET system, it is not a primitive.System.Stringis a full-fledged class, not a primitive.