Following this question, I see it's possible to pass a type to a method. Inside the method to which the type has been passed, how would an object be cast to that passed type? As a complication, class Foo
inherits from a class which I cannot change.
var x = FetchData();
Foo foo = new Foo(2, typeof(Gizmo)); // pass the Gizmo type
foo.Execute(x);
public class Foo : ThirdPartyLibrary.Operation
{
Type customtype;
public Foo(int i, Type passedtype) : base()
{
this.customtype=passedtype;
}
public override void Execute(ThirdPartyLibrary.Node node)
{
var record = ( ??? ) node.GetData(); // cast node to the type of customtype
}
}