/// <summary> /// Defaults the initializer. /// </summary> /// <param name="json">The json.</param> /// <returns>JsonWorkItemInitializer.</returns> private static JsonWorkItemInitializer DefaultInitializer(JToken json) { var initializer = new JsonWorkItemInitializer(); JProperty fields = ((JObject)json).Properties().FirstOrDefault(p => p.Name == "fields"); if (fields == null) { initializer.FieldInitializer = new ParameterizedLazyWithReset <JsonWorkItem, JsonFieldCollection>(DeferredLoadFields); initializer.FieldsMode = "DeferredLoadFields"; } else { initializer.FieldInitializer = new ParameterizedLazyWithReset <JsonWorkItem, JsonFieldCollection>(ParseFields); initializer.FieldsMode = "ParseFields"; } JProperty links = ((JObject)json).Properties().FirstOrDefault(p => p.Name == "relations"); if (links == null) { initializer.LinkInitializer = new ParameterizedLazyWithReset <JsonWorkItem, JsonLinkCollection>(DeferredLoadLinks); initializer.LinkMode = "DeferredLoadLinks"; } else { initializer.LinkInitializer = new ParameterizedLazyWithReset <JsonWorkItem, JsonLinkCollection>(ParseLinks); initializer.LinkMode = "ParseLinks"; } return(initializer); }
/// <summary> /// Initializes a new instance of the <see cref="JsonWorkItem" /> class. /// </summary> /// <param name="json">The json.</param> /// <param name="initializer">The initializer.</param> /// <exception cref="System.Exception"></exception> protected JsonWorkItem(JToken json, JsonWorkItemInitializer initializer) : base(json) { r_Fields = initializer.FieldInitializer; r_Links = initializer.LinkInitializer; if (r_Links == null) { throw new Exception(); } }
/// <summary> /// Froms the token. /// </summary> /// <param name="json">The json.</param> /// <returns>JsonRelatedLink.</returns> public static new JsonRelatedLink FromToken(JToken json) { var initializer = new JsonWorkItemInitializer { OtherItemInitializer = new ParameterizedLazyWithReset <JsonRelatedLink, JsonWorkItem>(o => { var retVal = JsonWorkItem.APIFactory().GetWorkItem(new Uri(sr_Url.Eval(o))); return(retVal); }), LinkTypeEndInitializer = new ParameterizedLazyWithReset <JsonRelatedLink, JsonLinkTypeEnd>(o => { JProperty property = ((JObject)o.JsonValue).Properties().FirstOrDefault(p => p.Name == "rel"); var retVal = new JsonLinkTypeEnd(property.Value); return(retVal); }) }; return(new JsonRelatedLink(json, initializer)); }
/// <summary> /// Initializes a new instance of the <see cref="JsonBackedObjectBase" /> class. /// </summary> /// <param name="json">The json.</param> /// <param name="initializer">The initializer.</param> protected JsonRelatedLink(JToken json, JsonWorkItemInitializer initializer) : base(json) { r_OtherItem = initializer.OtherItemInitializer; r_LinkTypeEnd = initializer.LinkTypeEndInitializer; }