neudeal
asked on
dynamic casting for generic types
hello,
I need to make a cast to IList<T> but I will not know what T is until runtime. Anyone know the best way to accomplish this... codeDOM perhaps?
Ultimately, I need to execute a statement like the following:
MethodInfo info;
Object obj;
IList<T> res = (IList<T>)info.Invoke(obj, new object[] { });
where:
the cast type will be info.ReturnType; i.e. info.ReturnType == IList<T>
or T will be info.ReturnParameter.Param eterType; i.e. info.ReturnType.ParameterT ype == T
Does this make sense?
Thanks,
Robert
I need to make a cast to IList<T> but I will not know what T is until runtime. Anyone know the best way to accomplish this... codeDOM perhaps?
Ultimately, I need to execute a statement like the following:
MethodInfo info;
Object obj;
IList<T> res = (IList<T>)info.Invoke(obj,
where:
the cast type will be info.ReturnType; i.e. info.ReturnType == IList<T>
or T will be info.ReturnParameter.Param
Does this make sense?
Thanks,
Robert
Let me understand. you are looking to pass an array of strings to a function that should return you a List of type T , probably having the strings you sent as one of its properties ???
ASKER
The method invoked by the MethodInfo instance described here will return an IList<> of some type T. T could be strings, or foos or bars... it will be an IList<> of whatever the MethodInfo.ReturnParameter is.
I guess the question is... is there a way for me to declare and assign an instance of IList<T> while learning what T is on the fly?
Thanks,
I guess the question is... is there a way for me to declare and assign an instance of IList<T> while learning what T is on the fly?
Thanks,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Forced accept.
Computer101
EE Admin
Computer101
EE Admin