C# simpler run time generics
Posted
by
Hellfrost
on Stack Overflow
See other posts from Stack Overflow
or by Hellfrost
Published on 2011-11-24T09:27:05Z
Indexed on
2011/11/24
9:51 UTC
Read the original article
Hit count: 292
Is there a way to invoke a generic function with a type known only at run time?
I'm trying to do something like:
static void bar()
{
object b = 6;
string c = foo<typeof(b)>();
}
static string foo<T>()
{
return typeof (T).Name;
}
Basically I want to decide on the type parameter only at run time, but the function I'm calling depends on the type parameter.
Also I know this can be done with reflections... but it's not the nicest solution to the problem...
I'm sort of looking for dynamic features in C#...
© Stack Overflow or respective owner