Home Ask Login Register

Developers Planet

Your answer is one click away!

user81993 February 2016

What is the point of CTypeDynamic?

I'm using reflection to serialize an object. Getting the values as objects is a real murder on performance due to late binding penalties. CType / DirectCast can get rid of most of it but I can't feed a type variable into it so currently I'm using a switch case block on the type variable to select the correct DirectCast.

It came to my attention that CTypeDynamic exists and takes type variables but the return type is Object so... it converts an object into an object, cool. That got me wondering, what is the purpose of this function?


Codexer February 2016

The CTypeDynamic function looks for dynamic information and performs the cast/conversion appropriately. This is different from the CType operator which looks for static information at compile time or relies on the types being IConvertible.

This function examines the object at runtime including looking for Shared (aka static) custom operators. As always, if you know the type then use CType, but if you need dynamic casting then you need to use CTypeDynamic.

More information here: http://blogs.msmvps.com/bill/2010/01/24/ctypedynamic/

Post Status

Asked in February 2016
Viewed 2,266 times
Voted 4
Answered 1 times


Leave an answer

Quote of the day: live life