You can use type inference to sort the trampoline by call:
dynamic x = something not strongly typed; CallFunctionWithInference(x); ... static void CallFunctionWithInference<T>(T ignored) { CallFunction<T>(); } static void CallFunction<T>() {
This will determine the type argument at runtime based on the runtime type of the value x , using the same type inference type that it would use if x had it as its compile time type. The parameter is present only for performing type inference operations.
Please note that unlike Darin, I believe that this is a useful method - in the same situations when pre-dynamics you end up calling a general method with reflection. You can do this part of the dynamic code, but keep the rest of the code (from the generic type down) by type. It allows you to make one step dynamic - only one bit where you do not know the type.
Jon skeet
source share