예제 #1
0
        public void TestCompareTo()
        {
            NullableKey <String> s = "hello";

            Assert.IsTrue(s.CompareTo("hello") == 0);
            s = null;
            Assert.IsTrue(s.CompareTo("hello") < 0);
        }
예제 #2
0
        public void TestGetHashCode()
        {
            NullableKey <String> s = "hello";

            Assert.IsTrue(s.GetHashCode() == "hello".GetHashCode());
            s = null;
            Assert.IsTrue(s.GetHashCode() == 0);
        }
예제 #3
0
        public void TestEquals()
        {
            NullableKey <String> s = "hello";

            Assert.IsTrue(s == "hello");
            s = null;
            Assert.IsTrue(s == null);
            Assert.IsFalse(s.Equals(0));
        }
예제 #4
0
 public void TestSerializeNullableKey()
 {
     using (MemoryStream stream = new MemoryStream()) {
         Writer             writer = new Writer(stream);
         NullableKey <int?> a      = 1;
         writer.Serialize(a);
         a = null;
         writer.Serialize(a);
         var data = stream.GetArraySegment();
         Assert.AreEqual("1n", Encoding.UTF8.GetString(data.Array, data.Offset, data.Count));
     }
 }
                public int GetHashCode(NullableKey <T> obj)
                {
                    if (obj == null || obj.Value == null)
                    {
                        return(0);
                    }                                                   // # Returning zero for hashcode indicating that the value is null
                    if (mComparer == null)
                    {
                        return(obj.Value.GetHashCode());
                    }

                    return(mComparer.GetHashCode(obj.Value));
                }
예제 #6
0
 public void TestSerializeArray()
 {
     using (MemoryStream stream = new MemoryStream()) {
         Writer writer = new Writer(stream);
         var    a      = new NullableKey <int?>[] {
             null, 1, 2, 3, 4, 5
         };
         writer.Serialize(a);
         writer.Serialize(a);
         var data = stream.GetArraySegment();
         Assert.AreEqual("a6{n12345}r0;", Encoding.UTF8.GetString(data.Array, data.Offset, data.Count));
     }
     using (MemoryStream stream = new MemoryStream()) {
         Writer writer = new Writer(stream);
         var    a      = new object[] {
             null, 1, 2, 3, 4, 5, "hello"
         };
         writer.Serialize(a);
         writer.Serialize(a);
         var data = stream.GetArraySegment();
         Assert.AreEqual("a7{n12345s5\"hello\"}r0;", Encoding.UTF8.GetString(data.Array, data.Offset, data.Count));
     }
 }
 public bool Equals(NullableKey <T> x, NullableKey <T> y)
 {
     return(mComparer.Equals(x.Value, y.Value));
 }
        public bool Remove(KeyValuePair <TKey, TValue> item)
        {
            KeyValuePair <NullableKey <TKey>, TValue> keyValuePair = new KeyValuePair <NullableKey <TKey>, TValue>(NullableKey <TKey> .Create(item.Key), item.Value);

            return(((ICollection <KeyValuePair <NullableKey <TKey>, TValue> >)mDictionary).Remove(keyValuePair));
        }
 public TValue this[TKey key]
 {
     get { return(mDictionary[NullableKey <TKey> .Create(key)]); }
     set { mDictionary.Add(NullableKey <TKey> .Create(key), value); }
 }
예제 #10
0
 public bool TryGetValue(TKey key, out TValue value)
 {
     return(mDictionary.TryGetValue(NullableKey <TKey> .Create(key), out value));
 }
예제 #11
0
 public bool Remove(TKey key)
 {
     return(mDictionary.Remove(NullableKey <TKey> .Create(key)));
 }
예제 #12
0
 public bool ContainsKey(TKey key)
 {
     return(mDictionary.ContainsKey(NullableKey <TKey> .Create(key)));
 }
예제 #13
0
 public void Add(TKey key, TValue value)
 {
     mDictionary.Add(NullableKey <TKey> .Create(key), value);
 }
예제 #14
0
 public override void Write(Writer writer, NullableKey <T> obj) => Serializer <T> .Instance.Serialize(writer, obj.Value);