J
jfbaro
Hi,
I am new to C# and I don't know how to cast dynamically an object to a
specific type . I have the object and its type (as a Type object).
For example, I read some data from a query (which has been created
dynamically) and get a list of objects and theirs types (string, Int64,
DateTime...). Now I need to put them into a BinaryWrite. Is there any
way of dynamically define which Write method to call?? I don't want to
have a BIG switch to test each possible Type.
I would like to have something similar to that:
Object obj = new Object(); \\ it comes from a datareader... let's
assume it is a string
objBinaryWriter.Write(obj as obj.GetType());
Thanks in advance
I am new to C# and I don't know how to cast dynamically an object to a
specific type . I have the object and its type (as a Type object).
For example, I read some data from a query (which has been created
dynamically) and get a list of objects and theirs types (string, Int64,
DateTime...). Now I need to put them into a BinaryWrite. Is there any
way of dynamically define which Write method to call?? I don't want to
have a BIG switch to test each possible Type.
I would like to have something similar to that:
Object obj = new Object(); \\ it comes from a datareader... let's
assume it is a string
objBinaryWriter.Write(obj as obj.GetType());
Thanks in advance