Exemple #1
0
 public KVNode(string name, object value) //as keyvalue
 {
     KeyName    = name;
     this.type  = KVNodeType.KeyValue;
     this.value = value;
     Child      = new List <KVNode>();
 }
Exemple #2
0
 public KVNode(string name, params KVNode[] children) //as root, parent
 {
     KeyName   = name;
     this.type = KVNodeType.Parent;
     Child     = new List <KVNode>();
     foreach (var c in children)
     {
         AppendNode(c);
     }
 }
Exemple #3
0
 public KVNode FindSingleNode(string key, KVNodeType type)
 {
     try
     {
         return(Child.Find(x => x.Type == type && x.KeyName.ToLower().Equals(key.ToLower())));
     }
     catch
     {
         return(null);
     }
 }
Exemple #4
0
 public KVNode(string name, bool root = false) //as root, parent
 {
     KeyName = name;
     if (root)
     {
         type = KVNodeType.Root;
     }
     else
     {
         type = KVNodeType.None;
     }
     Child = new List <KVNode>();
 }
Exemple #5
0
        public bool SetValue(object value, string key = null, bool create = true)
        {
            if (key == null && this.type != KVNodeType.Parent && this.type != KVNodeType.Root)
            {
                this.value = value;
                type       = KVNodeType.KeyValue;
                return(true);
            }
            var bring = FindSingleNode(key, KVNodeType.KeyValue);

            if (bring != null)
            {
                bring.SetValue(value);
                return(true);
            }
            else if (create == true)
            {
                AppendNode(new KVNode(key, value));
            }
            return(false);
        }
Exemple #6
0
 public void AppendNode(KVNode node)
 {
     if (type != KVNodeType.Root)
     {
         type = KVNodeType.Parent;
     }
     node.SetParent(this);
     this.value = null;
     if (node.Type == KVNodeType.KeyValue)
     {
         if (!Child.Exists(x => x.KeyName.Equals(node.KeyName)))
         {
             Child.Add(node);
         }
         else
         {
             SetValue(node.GetValue(), node.KeyName);
         }
     }
     else
     {
         Child.Add(node);
     }
 }