コード例 #1
0
        protected void AssertPrimitiveMap(PrimitiveMap map) {
            // use generic API to access entries
            Assert.AreEqual(a, map["a"], "generic map entry: a");
            Assert.AreEqual(b, map["b"], "generic map entry: b");
            Assert.AreEqual(c, map["c"], "generic map entry: c");
            Assert.AreEqual(d, map["d"], "generic map entry: d");
            Assert.AreEqual(e, map["e"], "generic map entry: e");
            Assert.AreEqual(f, map["f"], "generic map entry: f");
            Assert.AreEqual(g, map["g"], "generic map entry: g");
            Assert.AreEqual(h, map["h"], "generic map entry: h");
            Assert.AreEqual(i, map["i"], "generic map entry: i");
            Assert.AreEqual(j, map["j"], "generic map entry: j");
            Assert.AreEqual(k, map["k"], "generic map entry: k");
            Assert.AreEqual(l, map["l"], "generic map entry: l");
            //Assert.AreEqual(m, map["m"], "generic map entry: m");
            //Assert.AreEqual(n, map["n"], "generic map entry: n");

            // use type safe APIs
            Assert.AreEqual(a, map.GetBool("a"), "map entry: a");
            Assert.AreEqual(b, map.GetByte("b"), "map entry: b");
            Assert.AreEqual(c, map.GetChar("c"), "map entry: c");
            Assert.AreEqual(d, map.GetShort("d"), "map entry: d");
            Assert.AreEqual(e, map.GetInt("e"), "map entry: e");
            Assert.AreEqual(f, map.GetLong("f"), "map entry: f");
            Assert.AreEqual(g, map.GetString("g"), "map entry: g");
            Assert.AreEqual(h, map.GetBool("h"), "map entry: h");
            Assert.AreEqual(i, map.GetByte("i"), "map entry: i");
            Assert.AreEqual(j, map.GetShort("j"), "map entry: j");
            Assert.AreEqual(k, map.GetInt("k"), "map entry: k");
            Assert.AreEqual(l, map.GetLong("l"), "map entry: l");
            //Assert.AreEqual(m, map.GetList("m"), "map entry: m");
            //Assert.AreEqual(n, map.GetDictionary("n"), "map entry: n");

            IList list = map.GetList("m");
            Assert.AreEqual(2, list.Count, "list size");
			Assert.IsTrue(list.Contains("Item1"));
			Assert.IsTrue(list.Contains("Item2"));

            IDictionary dictionary = map.GetDictionary("n");
            Assert.AreEqual(5, dictionary.Count, "dictionary size");

			IDictionary childMap = (IDictionary) dictionary["childMap"];
			Console.WriteLine("Found childMap: " + childMap);
			
			Assert.IsNotNull(childMap);
			Assert.AreEqual("childMap", childMap["name"], "childMap[name]");
			
			IList childList = (IList) dictionary["childList"];
			Console.WriteLine("Found childList: " + childList);
			Assert.IsNotNull(childList);
			Assert.IsTrue(childList.Contains("childListElement1"));
        }
コード例 #2
0
        protected PrimitiveMap CreatePrimitiveMap()
        {
            PrimitiveMap map = new PrimitiveMap();
            
            map["a"] = a;
            map["b"] = b;
            map["c"] = c;
            map["d"] = d;
            map["e"] = e;
            map["f"] = f;
            map["g"] = g;
            map["h"] = h;
            map["i"] = i;
            map["j"] = j;
            map["k"] = k;
            map["l"] = l;
            map["m"] = m;
            map["n"] = n;

            return map;
        }
コード例 #3
0
 /// <summary>
 /// Unmarshalls the map from the given data or if the data is null just
 /// return an empty map
 /// </summary>
 public static PrimitiveMap Unmarshal(byte[] data)
 {
     PrimitiveMap answer = new PrimitiveMap();
     answer.dictionary = UnmarshalPrimitiveMap(data);
     return answer;
 }