private string StringifyJson (CommonJson jsonObject) { var type = jsonObject.GetType (); string dataKey; if (type == typeof (TimeEntryJson)) { dataKey = "time_entry"; } else if (type == typeof (ProjectJson)) { dataKey = "project"; } else if (type == typeof (ClientJson)) { dataKey = "client"; } else if (type == typeof (TaskJson)) { dataKey = "task"; } else if (type == typeof (WorkspaceJson)) { dataKey = "workspace"; } else if (type == typeof (UserJson)) { dataKey = "user"; } else if (type == typeof (TagJson)) { dataKey = "tag"; } else if (type == typeof (WorkspaceUserJson)) { dataKey = "workspace_user"; } else if (type == typeof (ProjectUserJson)) { dataKey = "project_user"; } else { throw new ArgumentException (String.Format ("Don't know how to handle JSON object of type {0}.", type), "jsonObject"); } var json = new JObject (); json.Add (dataKey, JObject.FromObject (jsonObject)); return json.ToString (Formatting.None); }
public static CommonData Import(this CommonJson json, IDataStoreContext ctx, Guid?localIdHint = null, CommonData mergeBase = null) { var type = json.GetType(); if (type == typeof(ClientJson)) { return(Import((ClientJson)json, ctx, localIdHint, (ClientData)mergeBase)); } else if (type == typeof(ProjectJson)) { return(Import((ProjectJson)json, ctx, localIdHint, (ProjectData)mergeBase)); } else if (type == typeof(ProjectUserJson)) { return(Import((ProjectUserJson)json, ctx, localIdHint, (ProjectUserData)mergeBase)); } else if (type == typeof(TagJson)) { return(Import((TagJson)json, ctx, localIdHint, (TagData)mergeBase)); } else if (type == typeof(TaskJson)) { return(Import((TaskJson)json, ctx, localIdHint, (TaskData)mergeBase)); } else if (type == typeof(TimeEntryJson)) { return(Import((TimeEntryJson)json, ctx, localIdHint, (TimeEntryData)mergeBase)); } else if (type == typeof(UserJson)) { return(Import((UserJson)json, ctx, localIdHint, (UserData)mergeBase)); } else if (type == typeof(WorkspaceJson)) { return(Import((WorkspaceJson)json, ctx, localIdHint, (WorkspaceData)mergeBase)); } else if (type == typeof(WorkspaceUserJson)) { return(Import((WorkspaceUserJson)json, ctx, localIdHint, (WorkspaceUserData)mergeBase)); } throw new InvalidOperationException(String.Format("Unknown type of {0}", type)); }