public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var obj = JObject.Load(reader); var type = obj["Type"].Value <string>(); State.IBuilder <State> result = null; switch (Enum.Parse(typeof(StateType), type)) { case StateType.Choice: result = ChoiceState.GetBuilder(); break; case StateType.Fail: result = FailState.GetBuilder(); break; case StateType.Parallel: result = ParallelState.GetBuilder(); break; case StateType.Pass: result = PassState.GetBuilder(); break; case StateType.Succeed: result = SucceedState.GetBuilder(); break; case StateType.Task: result = TaskState.GetBuilder(); break; case StateType.Wait: result = WaitState.GetBuilder(); break; case StateType.Map: result = MapState.GetBuilder(); break; } serializer.Populate(obj.CreateReader(), result); return(result); }