V
vtjumper
I'm building a C# interface to an existing messaging system. The
messaging system allows values of several types to be sent/recieved
over the interface.
What I want to do is use a generic class to produce values in the
system. For instance I could create class
MsgGenericValue<UInt16>() which would represent an unsigned value on
the interface.
My issue is converting from byte [] values to the generic type T.
So if I have a class: MsgGenericValue<T>
With a member
T _Value
I want do be able to do something like
if (_Value is Int32) _Value =
BitConverter.ToInt32(Bytes, 0);
But it doesn't compile - It can't convert from Int32 to 'T'
So how do I do this? Any thoughts would be greatly appreciated
Tom
messaging system allows values of several types to be sent/recieved
over the interface.
What I want to do is use a generic class to produce values in the
system. For instance I could create class
MsgGenericValue<UInt16>() which would represent an unsigned value on
the interface.
My issue is converting from byte [] values to the generic type T.
So if I have a class: MsgGenericValue<T>
With a member
T _Value
I want do be able to do something like
if (_Value is Int32) _Value =
BitConverter.ToInt32(Bytes, 0);
But it doesn't compile - It can't convert from Int32 to 'T'
So how do I do this? Any thoughts would be greatly appreciated
Tom