public void SingleValueDoesNotEqualNull() { SingleValue <int> sv = 42; Assert.False(sv.Equals(null)); Assert.False(sv.Equals((SingleValue <int>)null)); Assert.False(sv.Equals((SingleValue <MyBoolean>)null)); Assert.False(sv.Equals((ConfigItem)null)); }
public void SingleValueEqualsWorks() { { SingleValue <MyBoolean> sv1 = MyBoolean.TRUE; SingleValue <MyBoolean> sv2 = MyBoolean.TRUE; Assert.True(sv1.Equals(sv2)); } { SingleValue <MyBoolean> sv1 = MyBoolean.TRUE; SingleValue <MyBoolean> sv2 = MyBoolean.FILE_NOT_FOUND; Assert.False(sv1.Equals(sv2)); } { SingleValue <MyBoolean> sv1 = MyBoolean.FILE_NOT_FOUND; SingleValue <MyBoolean> sv2 = (MyBoolean)2; Assert.True(sv1.Equals(sv2)); } { SingleValue <int> sv1 = 42; SingleValue <int> sv2 = 42; Assert.True(sv1.Equals(sv2)); } }
/// <summary> /// Determines whether the specified object instance is considered equal to the current instance. /// </summary> /// <param name="obj">The object to compare with.</param> /// <returns>true if the objects are considered equal; otherwise, false.</returns> public override bool Equals(object obj) { // an indexable option cannot store null if (obj == null) { return(false); } if (obj is IndexableOption <T> option) { return(Equals(option)); } else { if (IsIndexed) { return(IndexedValues.Equals(obj)); } else { return(SingleValue.Equals(obj)); } } }