Hi
I need method "ToType" that takes value and type as parameter and converts it to respective type.
dim val as String = "1"
dim paramType as Type = Type.GetType("System.Int16")
dim myint as Int16 = ToType(val,paramType)
Regards
Dipesh
Hi
I need method "ToType" that takes value and type as parameter and converts it to respective type.
dim val as String = "1"
dim paramType as Type = Type.GetType("System.Int16")
dim myint as Int16 = ToType(val,paramType)
Regards
Dipesh
Dynamic Type Converion
Brent McCulloch
Use the CType(object, datatype) method or Convert class - as in Convert.ToInt32(...)
Look them up on MSDN for more info or F1 them from the IDE.
shadow_woman
If you hadn't rushed to answer then you would have read the subject. That clearly says "Dynamic Type Conversion". Hope you take time onwards.
vikrant
SoloCoder think before you post. I am loading assemblies at runtime, and then class, and then create an instance of it. Then invoke one of method with in it. The defintion of assemblies, class, method and it's parameters all are fetched from XML file.
<params>
<param type="System.Int32" name="parentID">12</param>
<param type="System.Int16" name="childrenID">152562</param>
</params>
Now we have to cast parentID i.e 12 and childrenID 152562 to Int32 and Int16 respectively and put it that to an infoArgsValue.
Dim infoArgsName(2) As String
Dim infoArgsValue(2) As Object
Dim paramType as Type
paramType = Type.GetType(tempNode.Attributes("type").Value)
Now that I have type in my variable, i would like to cast param's innerText to one that is defined on type.
GapToN
I dont like your tone Dipesh - your initial post which I answered said nothing about dynamically loading assemblies etc. Just type conversion. Ctype can be used with a string as the type anyway if you got the brains to figure it out...
And even marked my reply as the answer... go figure... perhaps you had a rough day