Question: I've got this class with a method that returns an object:

```
public class Deserializer<T>
{
    public static T FromJson(string json)
    {
        return new JavaScriptSerializer().Deserialize<T>(json);
    }   
}

```

And I've got a Type. How do I create an instance of the Deserializer class based on a this type? The following obviously doesn't work:

```
var type = typeOf(MyObject);
var foo = Deserializer<type>.FromJson(json);

```

Answer: 
You could provide a non-generic version as well for consumers that don't know the type at compile-time (which is a good practice by the way when you are exposing an API):

```
public class Deserializer
{
    public static T FromJson<T>(string json)
    {
        return new JavaScriptSerializer().Deserialize<T>(json);
    }

    public static object FromJson(string json, Type type)
    {
        return new JavaScriptSerializer().Deserialize(json, type);
    }
}

```

Now, consumers that know the type at compile-time:

```
Foo foo = Deserializer.FromJson<Foo>(json);

```

and consumers that don't know the type at compile-time:

```
Type type = ...
object instance = Deserializer.FromJson(json, type);

```
This is how you could do it, but it's not exactly optimal unless you absolutely must do it this way. Go with one of the other answers if you can!

```
dynamic result = typeof(Deserializer<>).MakeGenericType(type)
    .InvokeMember("FromJson", BindingFlags.Public | BindingFlags.Static |
                              BindingFlags.InvokeMethod, null, null,
                  new [] { json });

```