Given a method such as this
public
List<T> GetPickedIds<T>()Is there any way I can call this method passing in a Type for T derived from elsewhere? What I mean is instead of typing GetPickedIds<int> I could do something like
Type type = GetType("int");
GetPickedIds<type>;
Any thoughts?
TIA.
hi razorkai
i'm pretty sure you can't
generics mechanism need to know at compile time what kind of type it handle.
i think that one of the purposes of generics is to simplify the implementation of
strong Type classes.
if what you're suggesting is true that what would
'GetPickedIds<type>[0]' returns?
Andrés
Don't dangle the carrot like that! <g> How could I achieve this? I have been trying for ages but figured it was not possible. Any example code would be appreciated.
John.
hi.
i tried it' just 4 fun :) and i think you're mistaken.
when you try this code you get InvalidOperationException: "Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true."
public static void test<T>() { Console.WriteLine(typeof(T).FullName); }
|
Copyright (c) Marimer LLC