This doesn't compile, but what I'm trying to do is simply casting object to 't' which is passed to the function?
public void My_Func(Object input, Type t)
{
(t)object ab = TypeDescriptor.GetConverter(t).ConvertFromString(input.ToString());
}
You could do something like:
object ab = Convert.Changetype(input, t);
however, it looks like you want to use ab
in a strongly-typed manner, which you can only do so by using generics:
public void My_Func<T>(Object input)
{
T ab = (T)Convert.ChangeType(input, typeof(T));
}
public void My_Func(Object input, Type t)
{
object test = new object();
test = Convert.ChangeType(test, t);
test = TypeDescriptor.GetConverter(t).ConvertFromString(input.ToString());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With