Remember that casting a reference-type object does not actually convert the object at all. All casting does is to alter the lens (interface) through which you are accessing the object. With that in mind, the following line is totally useless:
SomeVar = CType(action, MyOwntype)
SomeVar
is As Object
, therefore, casting the object to any particular type first, before setting SomeVar
, is pointless. Once SomeVar
is pointing to it, it will be viewing it As Object
, regardless of the interface through which it was previously viewed/referenced.
The way to do what you want to do would be to create a new variable of the specific type and set that variable to the object. If you have Option Strict On
, as you most likely ought to, you'll need to cast it when you set the variable. But, once you have set the variable, then you can access the object through that variable (with full intellisense) without having to re-cast each time. For instance:
Dim mySpecificVar As MyOwnType = DirectCast(action, MyOwnType)
SomeControl.Text = mySpecificVar.Property
' ...