If I wrote this code:
typeof(myType).TypeHandle
Would it use reflection?
How much different from:
Type.GetType(string).TypeHandle
is it?
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.
Well, it really depends on what you mean by ‘reflection’ – which isn’t exactly strictly defined.
There are two parts to using
typeofin the compiled code. The first is the use of theldtokenwhich is an IL instruction described like this in the CIL spec:After this, a call to
Type.GetTypeFromHandleis made.This is all significantly quicker than
Type.GetType(string)however, if that’s what you were concerned with.EDIT: I just noticed the TypeHandle part of your question. As far as I can see, the MS compiler doesn’t optimise away the call to GetTypeFromHandle and then TypeHandle, even though I guess you really only need the
ldtokencall.Whether all of this counts as ‘reflection’ or not is up to you…