Example #1
0
        public void TestBasics()
        {
            var tags = new HaystackDictionary();

            tags.Add("id", new HaystackReference("aaaa-bbbb"));
            tags.Add("site", new HaystackMarker());
            tags.Add("geoAddr", new HaystackString("Richmond, Va"));
            tags.Add("area", new HaystackNumber(1200, "ft"));
            tags.Add("date", new HaystackDate(2000, 12, 3));
            tags.Add("null", null);

            // size
            Assert.AreEqual(5, tags.Count);
            Assert.IsFalse(tags.IsEmpty());

            // configured tags
            Assert.IsTrue(tags.Get("id").Equals(new HaystackReference("aaaa-bbbb")));
            Assert.IsTrue(tags.Get("site").Equals(new HaystackMarker()));
            Assert.IsTrue(tags.Get("geoAddr").Equals(new HaystackString("Richmond, Va")));
            Assert.IsTrue(tags.Get("area").Equals(new HaystackNumber(1200, "ft")));
            Assert.IsTrue(tags.Get("date").Equals(new HaystackDate(2000, 12, 3)));
            Assert.ThrowsException <HaystackUnknownNameException>(() => tags.Get("null"));

            // missing tag
            Assert.IsFalse(tags.ContainsKey("foo"));
            Assert.ThrowsException <HaystackUnknownNameException>(() => tags.Get("foo"));
        }
 public static TValue GetUnchecked <TValue>(this HaystackDictionary dict, string name)
     where TValue : HaystackValue
 {
     if (dict.ContainsKey(name))
     {
         return(dict.Get <TValue>(name));
     }
     return(null);
 }
Example #3
0
        public void TestCheckedImplicitMissing()
        {
            var tags = new HaystackDictionary();

            tags.Get("foo");
        }
 public static double GetDouble(this HaystackDictionary dict, string name)
 {
     return(dict.Get <HaystackNumber>(name).Value);
 }
 public static HaystackReference GetReference(this HaystackDictionary dict, string name)
 {
     return(dict.Get <HaystackReference>(name));
 }
 public static bool GetBoolean(this HaystackDictionary dict, string name)
 {
     return(dict.Get <HaystackBoolean>(name).Value);
 }
 public static string GetString(this HaystackDictionary dict, string name)
 {
     return(dict.Get <HaystackString>(name).Value);
 }