Example #1
0
 public KeyObjectValueNode
 (
     JToken jToken
     , string name
     , KeyValueNode parentJsonNode
 )
 {
     Instance             = this;
     AsKeyObjectValueNode = this;
     Parent     = parentJsonNode;
     NodeJToken = jToken;
     Key        = name;
 }
Example #2
0
 public ObjectValueNode
 (
     JToken jToken
     , object value
     , KeyValueNode parentJsonNode
 )
 {
     Instance          = this;
     AsObjectValueNode = this;
     Parent            = parentJsonNode;
     NodeJToken        = jToken;
     //Value = value;
 }
Example #3
0
 //private Dictionary<int, KeyValueNode>
 //        _intsKeysValuesDictionary
 //                = new Dictionary<int, KeyValueNode>();
 public void AddChild
 (
     string key
     , KeyValueNode jsonNode
 )
 {
     _stringsKeysValuesDictionary
     .Add
     (
         key
         , jsonNode
     );
 }
Example #4
0
 public KeyValuePairNode
 (
     JToken jToken
     , string name
     , object value
     , KeyValueNode parentJsonNode
 )
 {
     Instance           = this;
     AsKeyValuePairNode = this;
     Parent             = parentJsonNode;
     NodeJToken         = jToken;
     Key = name;
     //_value = value;
 }
Example #5
0
 public static KeyValueNode CreateFromJToken
 (
     JToken jToken
     , KeyValueNode parentJsonNode
     , int arrayElementIndex = -1
 )
 {
     if (jToken is JValue)
     {
         var jsonValueNode
             = new ObjectValueNode
               (
                   jToken
                   , ((JValue)jToken).Value
                   , parentJsonNode
               );
         if (parentJsonNode is KeyArrayValueNode)
         {
             jsonValueNode.ArrayElementIndex = arrayElementIndex;
         }
         return(jsonValueNode);
     }
     else if (jToken is JProperty)
     {
         JProperty jProperty = (JProperty)jToken;
         if (jProperty.Value is JValue)
         {
             var jsonPropertyNode
                 = new KeyValuePairNode
                   (
                       jToken
                       , jProperty.Name
                       ,
                       (
                           (JValue)jProperty.Value
                       ).Value
                       , parentJsonNode
                   );
             if (parentJsonNode != null)
             {
                 parentJsonNode
                 .AddChild
                 (
                     jProperty.Name
                     , jsonPropertyNode
                 );
             }
             return(jsonPropertyNode);
         }
         else if (jProperty.Value is JArray)
         {
             var jsonArrayNode
                 = new KeyArrayValueNode
                   (
                       jToken
                       , jProperty.Name
                       , parentJsonNode
                   );
             if (parentJsonNode != null)
             {
                 parentJsonNode
                 .AddChild
                 (
                     jProperty.Name
                     , jsonArrayNode
                 );
             }
             int i = 0;
             jsonArrayNode
             .Children
                 =
                     (
                         (JArray)jProperty.Value
                     )
                     .Children()
                     .Select
                     (
                         (x) =>
             {
                 var r = CreateFromJToken
                         (
                     x
                     , jsonArrayNode
                     , i
                         );
                 i++;
                 return(r);
             }
                     );
             jsonArrayNode
             .NodesArray
                 = jsonArrayNode
                   .Children
                   .ToArray();
             return(jsonArrayNode);
         }
         else if (jProperty.Value is JObject)
         {
             var jsonObjectNode
                 = new KeyObjectValueNode
                   (
                       jToken
                       , jProperty.Name
                       , parentJsonNode
                   );
             if (parentJsonNode != null)
             {
                 parentJsonNode
                 .AddChild
                 (
                     jProperty.Name
                     , jsonObjectNode
                 );
             }
             jsonObjectNode
             .Children =
                 (
                     (JObject)jProperty.Value
                 )
                 .Children()
                 .Select
                 (
                     (x) =>
             {
                 var r = CreateFromJToken
                         (
                     x
                     , jsonObjectNode
                         );
                 return(r);
             }
                 );
             jsonObjectNode
             .Children
             .ToList();
             return(jsonObjectNode);
         }
         else
         {
             throw new Exception("Unknown JProperty");
         }
     }
     else if (jToken is JArray)
     {
         var jsonArrayNode = new KeyArrayValueNode
                             (
             jToken
             , null
             , parentJsonNode
                             );
         jsonArrayNode
         .Children =
             (
                 (JArray)jToken
             )
             .Children()
             .Select
             (
                 (x) =>
         {
             var r = CreateFromJToken
                     (
                 x
                 , jsonArrayNode
                     );
             return(r);
         }
             );
         jsonArrayNode
         .Children
         .ToList();
         return(jsonArrayNode);
     }
     else if (jToken is JObject)
     {
         KeyObjectValueNode jsonObjectNode = new KeyObjectValueNode
                                             (
             jToken
             , null
             , parentJsonNode
                                             );
         jsonObjectNode
         .Children =
             (
                 (JObject)jToken
             )
             .Children()
             .Select
             (
                 (x) =>
         {
             var r = CreateFromJToken
                     (
                 x
                 , jsonObjectNode
                     );
             return(r);
         }
             );
         jsonObjectNode
         .Children
         .ToList();
         return(jsonObjectNode);
     }
     else
     {
         throw new Exception("Unknown JToken");
     }
 }