I need to make a cast with a type passed into a variaable, this is possible ? if yes, how to do this ?
Inside of ForEach action I need to make the cast, I don't have the type, but just a instance of object....
for example: ( of course this is just a hypothetical example to show what I'm trying to do )
private static void ForEach(Type[] tp, Action<string, Type> action)
{
for (int i = 0; i < tp.Length; i++)
action("test", tp[i]);
}
static void Main()
{
Type[] tp = new Type[]
{
typeof(int),
typeof(string),
typeof(double)
};
ForEach(tp, (x, y) =>
{
// make the cast here
// var aaaa = (y)(x);
});
}
static T Cast<T>(object input)
{
return (T)input;
}