public void Test_BDict_class()
        {
            BDictionary bdict = new BDictionary();

            Assert.IsNotNull(bdict);
            Assert.AreEqual("de", bdict.EncodeAsString());

            IBObject obj = null;

            Assert.Throws(typeof(ArgumentNullException), () => { bdict.Add("key", obj); });

            bdict.Add("str", "test");
            bdict.Add("number", 1234);
            Assert.AreEqual("d6:numberi1234e3:str4:teste", bdict.EncodeAsString());

            obj = bdict.Get <BString>("str");
            Assert.AreEqual("test", obj.ToString());

            obj = bdict.Get <BNumber>("number");
            Assert.AreEqual(1234, ((BNumber)obj).Value);

            Assert.AreEqual(2, bdict.Count);
            bdict.Clear();
            Assert.AreEqual(0, bdict.Count);
        }
        public void Test_BList_class()
        {
            BList blist = new BList();

            Assert.IsNotNull(blist);
            Assert.AreEqual("le", blist.EncodeAsString());

            IBObject obj = null;

            Assert.Throws(typeof(ArgumentNullException), () => { blist.Add(obj); });

            blist.Add("test");
            blist.Add(1234);
            Assert.AreEqual("l4:testi1234ee", blist.EncodeAsString());

            obj = blist.Get <BString>(0);
            Assert.AreEqual("test", obj.ToString());

            obj = blist.Get <BNumber>(1);
            Assert.AreEqual(1234, ((BNumber)obj).Value);

            var blistCopy = new BList(blist.Value);

            Assert.AreEqual("l4:testi1234ee", blistCopy.EncodeAsString());

            Assert.AreEqual(2, blistCopy.Count);
            blistCopy.Clear();
            Assert.AreEqual(0, blistCopy.Count);
        }
Esempio n. 3
0
        private static object GetFromBDicRec(BDictionary dic, string[] path, int level)
        {
            IBObject ibo = dic[path[level]];

            if (ibo == null)
            {
                return(null);
            }

            if (level == path.Length - 1)
            {
                if (ibo.GetType() == typeof(BString))
                {
                    return(ibo.ToString());
                }
                else if (ibo.GetType() == typeof(BNumber))
                {
                    return((int)((BNumber)ibo).Value);
                }
                else if (ibo.GetType() == typeof(BDictionary))
                {
                    return(((BDictionary)ibo).Value);
                }
            }
            else
            if (ibo.GetType() == typeof(BDictionary))
            {
                return(GetFromBDicRec((BDictionary)ibo, path, level + 1));
            }

            return(null);
        }
Esempio n. 4
0
 /// <summary>
 ///   Visits the specified item.
 /// </summary>
 /// <param Name = "item">The item.</param>
 public void Visit(IBObject item)
 {
     Console.WriteLine(item.ToString());
 }
Esempio n. 5
0
 /// <summary>
 ///   Visits the specified item.
 /// </summary>
 /// <param Name = "item">The item.</param>
 public void Visit(IBObject item)
 {
     Console.WriteLine(item.ToString());
 }