I want to create a method that takes a dynamic input parameter and returns a dynamic that I can use to fill a typed variable. Is there a way to get the type of the variable being assigned to from within the method?
double dbl = AssignValue("Hello");
public dynamic AssignValue(dynamic ValueToAssign)
{
Type type = //do something to get the type of variable "dbl"
switch (type.Name)
{
case "Double":
return double.Parse(AssignValue);
break;
case "Decimal":
return decimal.Parse(AssignValue);
break;
//...
}
}
I tried to locate something in the StackFrame but, with no luck.
Any terminology to research further would be very much appreciated as well.