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
The opensource framework Dynamitey has a static method that does late binding using DLR including cast conversion among others.
dynamic Cast(object obj, Type castTo){
return Dynamic.InvokeConvert(obj, castTo, explict:true);
}
The advantage of this over a Cast
called using reflection, is that this will also work for any IDynamicMetaObjectProvider
that has dynamic conversion operators, ie. TryConvert on DynamicObject
.