I would like to implement a method with the following signature
dynamic Cast(object obj, Type castTo);
Anyone know how to do that? obj defi
You can use the expression pipeline to achieve this:
public static Func
which you can invoke like:
object objAsDesiredType = Caster(desiredType)(obj);
Drawbacks: The compilation of this lambda is slower than nearly all other methods mentioned already
Advantages: You can cache the lambda, then this should be actually the fastest method, it is identical to handwritten code at compile time