예제 #1
0
        public static FoxBlob FromJson(string json)
        {
            var blob = new FoxBlob();

            blob.ReadJson(json);

            return(blob);
        }
예제 #2
0
        public FoxBlob Clone()
        {
            var clone = new FoxBlob();

            clone.ReadJson(ToString());

            return(clone);
        }
예제 #3
0
 public void SetBlob(string key, FoxBlob value)
 {
     ValidateKey(key);
     if (_entries[key].GetValue() is FoxBlob blob)
     {
         blob.Dispose();
     }
     _entries[key].SetBlob(value);
 }
예제 #4
0
        public FoxBlob GetBlob(FoxBlob _default)
        {
            Validate(BlobKind.Blob);
            if (_value is FoxBlob result)
            {
                return(result);
            }

            return(_default);
        }
예제 #5
0
 private static void GetJsonData(FoxBlob level, IDictionary <string, object> current)
 {
     foreach (var entry in level.Entries.OrderBy(x => x.Key))
     {
         if (entry.Value.Kind != BlobKind.Blob)
         {
             current.Add(entry.Key, entry.Value.GetValue());
         }
         else
         {
             var data = new Dictionary <string, object>();
             GetJsonData(entry.Value.GetBlob(), data);
             current.Add(entry.Key, data);
         }
     }
 }
예제 #6
0
 public void SetBlob(FoxBlob value)
 {
     Kind   = BlobKind.Blob;
     _value = value;
 }
예제 #7
0
        private void Parse(object data, FoxBlob level)
        {
            if (data is Dictionary <string, object> == false)
            {
                return;
            }

            foreach (var entry in (Dictionary <string, object>)data)
            {
                if (entry.Value is JObject obj)
                {
                    Parse(obj.ToObject <Dictionary <string, object> >(), level.FetchBlob(entry.Key));
                    continue;
                }

                if (entry.Value is JArray list)
                {
                    var pList = list.Cast <object>().ToList();
                    if (level.Contains(entry.Key))
                    {
                        var en = level.GetList <object>(entry.Key);
                        pList.AddRange(en);
                        level.SetList(entry.Key, pList);
                    }
                    else
                    {
                        level.SetList(entry.Key, pList);
                    }
                    pList.Clear();
                    continue;
                }

                if (entry.Value == null)
                {
                    level.SetString(entry.Key, null);
                    continue;
                }

                if (entry.Value is string str)
                {
                    level.SetString(entry.Key, str);
                    continue;
                }

                if (entry.Value is long lon)
                {
                    level.SetNumber(entry.Key, lon);
                    continue;
                }

                if (entry.Value is bool bol)
                {
                    level.SetBool(entry.Key, bol);
                    continue;
                }

                if (entry.Value is double dou)
                {
                    level.SetDouble(entry.Key, dou);
                    continue;
                }
            }
        }
예제 #8
0
 public void MergeFrom(FoxBlob blob)
 {
     ReadJson(blob.ToString());
 }
예제 #9
0
 public FoxBlob GetBlob(string key, FoxBlob _default)
 {
     return(!_entries.ContainsKey(key) ? _default : _entries[key].GetBlob(_default));
 }