Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CType in VB.NET with dynamic second parameter (type)

In VB.NET CType can be used to convert one type to another.

CType(expression,type)

I have the "expression" stored in an instance object class, say "objExp". I have the "type" stored in an instance of Type class, say"objType".

I am trying CType(objExp, objType) I am getting compile error, how should I go about it ? "objType" is fetched and assigned at runtime.

like image 445
Brij Avatar asked Mar 06 '13 16:03

Brij


2 Answers

Have you looked into the method CTypeDynamic()? The second parameter (ie: The Type) can be set dynamically. Great for when you are using Reflection.

For example:

CTypeDynamic(strValueToConvert, objTypeToConvertTo)
like image 70
ESB Developer Avatar answered Oct 21 '22 17:10

ESB Developer


This is simply not possible. The CType expression must be passed a Type instance which is known at compile time like Integer, String, etc ... It does not accept values which are of type Type

like image 30
JaredPar Avatar answered Oct 21 '22 16:10

JaredPar