What's the best way to call a generic method when the type parameter isn't known at compile time, but instead is obtained dynamically at runtime?
Consider the following sample code - inside the Example() method, what's the most concise way to invoke GenericMethod() using the type stored in the myType variable?
public class Sample
{
public void Example(string typeName)
{
Type myType = FindType(typeName);
// what goes here to call GenericMethod<T>() ?
GenericMethod<myType>(); // This doesn't work
// what changes to call StaticMethod<T>() ?
Sample.StaticMethod<myType>(); // This also doesn't work
}
public void GenericMethod<T>()
{
...
}
public static void StaticMethod<T>()
{
...
}
}