Esempio n. 1
0
 /// <summary>
 /// Does a depth-first traversal of the properties of the given object recursively, depth-first.
 ///
 /// p-code:
 ///   if (link.query is empty) {
 ///     for each member {
 ///       using link.rel and link.href, format a link and attach it to the member;
 ///       ====>>>
 ///         Q. BUT, __HOW__ do we get the parameters from the request?
 ///         A. We do not get them from the call, we get them from the response.
 ///       ====>>>
 ///     }
 ///   } else {
 ///       propertyValue = obj.Properties(car(link.query));
 ///       remainingLink = copyOf(link);
 ///       remainingLink.query = cdr(remainingLink.query);
 ///       call walk(propertyValue, remainingLink);
 ///     }
 ///   }
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="link"></param>
 private void Walk(JToken obj, LinkAttribute link)
 {
     if (link.query == null)
     {
         JObject linkingObject = obj as JObject;
         // construct an object in serial, then deserialize it and insert it
         var linkInstance = new { rel = link.rel, href = link.href.ResolveParameters(obj) };
         if (linkInstance.href != null)
         {
             if (linkingObject.Property("links") == null)
             {
                 linkingObject.Add("links", new JArray());
             }
             (linkingObject.Property("links").Value as JArray).Add(JObject.FromObject(linkInstance));
         }
     }
     else
     {
         LinkAttribute remainingLink  = link.NextLayer;
         string        propertySought = link.query[0];
         JToken        propertyValue;
         if (propertySought == "[]")
         {
             foreach (JToken arrayMember in (obj as JArray))
             {
                 Walk(arrayMember, remainingLink);
             }
         }
         else
         {
             if ((obj as JObject).TryGetValue(propertySought, out propertyValue) && propertyValue != null)
             {
                 Walk(propertyValue, remainingLink);
             }
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Does a depth-first traversal of the properties of the given object recursively, depth-first.
 /// 
 /// p-code:
 ///   if (link.query is empty) {
 ///     for each member {
 ///       using link.rel and link.href, format a link and attach it to the member;
 ///       ====>>> 
 ///         Q. BUT, __HOW__ do we get the parameters from the request? 
 ///         A. We do not get them from the call, we get them from the response.
 ///       ====>>>
 ///     }
 ///   } else {
 ///       propertyValue = obj.Properties(car(link.query));
 ///       remainingLink = copyOf(link);
 ///       remainingLink.query = cdr(remainingLink.query);
 ///       call walk(propertyValue, remainingLink);
 ///     }
 ///   }
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="link"></param>
 private void Walk(JToken obj, LinkAttribute link)
 {
     if (link.query == null) {
         JObject linkingObject = obj as JObject;
         // construct an object in serial, then deserialize it and insert it
         var linkInstance = new { rel = link.rel, href = link.href.ResolveParameters(obj) };
         if (linkInstance.href != null) {
             if (linkingObject.Property("links") == null) {
                 linkingObject.Add("links", new JArray());
             }
             (linkingObject.Property("links").Value as JArray).Add(JObject.FromObject(linkInstance));
         }
     } else {
         LinkAttribute remainingLink = link.NextLayer;
         string propertySought = link.query[0];
         JToken propertyValue;
         if (propertySought == "[]") {
             foreach (JToken arrayMember in (obj as JArray)) {
                 Walk(arrayMember, remainingLink);
             }
         } else {
             if ((obj as JObject).TryGetValue(propertySought, out propertyValue) && propertyValue != null) {
                 Walk(propertyValue, remainingLink);
             }
         }
     }
 }