in ClientLibrary/messages/Action.cs [29:50]
public static Action Parse(string json)
{
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(json)))
{
try
{
// Deserialize just the action field to get the type
var jsonSerializer = new DataContractJsonSerializer(typeof(Action));
var a = jsonSerializer.ReadObject(ms) as Action;
// Deserialize again into the appropriate type
ms.Position = 0;
jsonSerializer = new DataContractJsonSerializer(Types[a.Type]);
a = jsonSerializer.ReadObject(ms) as Action;
return a;
}
catch (Exception e)
{
ms.Position = 0;
throw new MalformedActionException("Received an action which couldn't be understood: " + json, e);
}
}
}