public static object TypeCast(object obj, Type t) { try { var param = Expression.Parameter(obj.GetType()); return Expression.Lambda(Expression.Convert(param, t), param) .Compile().DynamicInvoke(obj); } catch (TargetInvocationException ex) { throw ex.InnerException; } }
106500cookie-checkC# Cast type with Type class