assign datatype to incoming streaming data

RonMexico

Member
Joined
Aug 10, 2005
Messages
7
Location
Morgantown, WV
Programming Experience
5-10
I'm developing a component to read in raw streamed data. I want this component to have a property that allows the user to specify the datatype of the incoming data. I would like to use the .net enumeration to set this. The closest thing that I have found is to set the property as dbtype. However I do not think that this is right. Any ideas?
 
Can you declare a variable as a variable data type. I know that doesn't make too much sense so I'll give a quick example.

Dim strDataType as String = Int
Dim Parameter as strDataType

Then Parameter will be of type Int. Is this possible?
 
OK I'm actually pretty bad at explaining what I need to do. I think I can explain it better now. I'm developing a component. That component has several properties. One property is ParameterDatatype and Another is ParameterValue. My code looks like this. Where there's an X, I want to set as whatever they selected in the drop down for the Parameter datatype.

<DesignerSerializationVisibility DesignerSerializationVisibility.Visible)> _
Public Property ParameterDatatype () as TypeCode
Get
Return _ParameterDataType
End Get
Set (ByVal Value as TypeCode)
_ParamerterDataType = Value
End Set
End Property

<DesignerSerializationVisibility DesignerSerializationVisibility.Visible)> _
Public Property ParameterValue () as X
Get
Return _ParameterValue
End Get
Set (ByVal Value as X)
_ParameterValue = Value
End Set
End Property
 
I'm quite sure you cannot do it as you have shown. You would have to declare the ParameterValue property as type Object. You could then assign or return any type of object you want, which could then be cast as the correct type. That's how the types work for command parameters. You could either create an enumeration of your own to represent the valid types or you could declare the ParameterDataType property as type Type. You can get a Type object like this:
VB.NET:
GetType(Integer)
I don't know how to use a Type object to create an object of that type other than to use a series of If statements to choose which type of object to create. You may be able to use Reflection but that's not my forte.
 
Thanks for all of the help. I think that you are right about using the reflection namespace. I still have figured it out but you have given me a lot of good ideas of where to look. Once I get it figured out I'll post the answer. Thanks again for the help.
 
Back
Top