Suppose the following code:
public struct Result
{
public object objectResult
public Type objectType;
}
Result resultado = CualquierFuncion();
The CualquierFuncion
function would be something like this:
public Result CualquierFuncion()
{
Result result;
...
...
result.objectResult = myNewUnknowTypedObject;
result.objectType = myNewUnknowTypedObject.GetType();
return result
}
What I want to do (or know if it is possible to do and how) is something like the following:
var xxx = (result.objectType) result.objectResult;
I know that the direct typecast will not work, but is it possible to do this in any way other than by comparing the saved type value with the different expected types?