public void TestCompareTo() { NullableKey <String> s = "hello"; Assert.IsTrue(s.CompareTo("hello") == 0); s = null; Assert.IsTrue(s.CompareTo("hello") < 0); }
public void TestGetHashCode() { NullableKey <String> s = "hello"; Assert.IsTrue(s.GetHashCode() == "hello".GetHashCode()); s = null; Assert.IsTrue(s.GetHashCode() == 0); }
public void TestEquals() { NullableKey <String> s = "hello"; Assert.IsTrue(s == "hello"); s = null; Assert.IsTrue(s == null); Assert.IsFalse(s.Equals(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)); }
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); } }
public bool TryGetValue(TKey key, out TValue value) { return(mDictionary.TryGetValue(NullableKey <TKey> .Create(key), out value)); }
public bool Remove(TKey key) { return(mDictionary.Remove(NullableKey <TKey> .Create(key))); }
public bool ContainsKey(TKey key) { return(mDictionary.ContainsKey(NullableKey <TKey> .Create(key))); }
public void Add(TKey key, TValue value) { mDictionary.Add(NullableKey <TKey> .Create(key), value); }
public override void Write(Writer writer, NullableKey <T> obj) => Serializer <T> .Instance.Serialize(writer, obj.Value);