OK.
I have a set of data in the form of JSON. Each object represents one of a number of sub-classes from a single base class and one of the fields in the JSON object holds the name of sub-class
EDIT: I've obviously phrased the question badly; let me try again
Assume I'm making a number of calls to a spell that, with each call returns a JSON object. Each object looks a bit like this ...
{
"type":"FooA",
"FieldA":"AA",
"FieldB":"AB"
}
Now, whilst each object looks to have the same structure as the others, they actually represent very different classes. The appropriate type is stored in the 'type' field.
I can pass the JSON to a method that does something like this...
public Foo MakeFoos(string json)
{
var super = JsonConvert.Deserialize<Foo>(json);
switch(super.Type)
{
case "FooA":
return JsonConvert.Deserialize<FooA>(json);
case "FooB":
return JsonConvert.Deserialize<FooB>(json);
case "FooC":
return JsonConvert.Deserialize<FooC>(json);
case "FooD":
return JsonConvert.Deserialize<FooD>(json);
}
}
What I would like to know is if there is a way of creating and instance of the correct type for each entry without having to deserialize the object twice.