Q:

Use a type generated at runtime

I've several classes which I'd like to select and instantiate at run time. For example:
public class MyClassA{ 
  public int property1 {get; set;}
  public string property2 {get; set;}
}

public class MyClassB{ 
  public int property1 {get; set;}
  public string property3 {get; set;}
}

Let's say, MyClassB was selected at runtime: 
Type t = Type.GetType("MyNamespace.MyClassB");
Object myType = Activator.CreateInstance(t);

Now, i'd like to use myType as a type to pass to other classes/methods like this.
myType myDeserializedObject = JsonConvert.DeserializeObject<myType>(MyJsonString);

Code never compiles throwing "myType is a variable but is used like a type" error.
Is there any way or workaround to convert the activated instance to a type? Let me know if there is any other approach I should look into.
Thanks!

A:

You cant pass in a variable Type as a generic. Instead use
var myDeserializedObject = JsonConvert.DeserializeObject(MyJsonString, t);

