Beispiel #1
0
        public void Just()
        {
            var             a     = new object();
            IMaybe <object> justA = Maybe.Just(a);

            Assert.That(justA.Exists, Is.True);
            Assert.That(a, Is.SameAs(justA.Value));

            Assert.That(Maybe.Of(a), Is.EqualTo(justA));
            Assert.That(justA.Equals(null), Is.False);
            Assert.That(Maybe.Just(a), Is.EqualTo(justA));
            Assert.That(Maybe.Just("b"), Is.Not.EqualTo(justA));
            Assert.That(Maybe.Just <object>("b"), Is.Not.EqualTo(justA));
            Assert.That(Maybe.Nothing <string>(), Is.Not.EqualTo(justA));
            Assert.True(justA.Equals(justA));

            Assert.That(Maybe.Just("a").ToString(), Is.EqualTo("Just(a)"));

            Assert.That(justA.GetHashCode(), Is.EqualTo(justA.Value.GetHashCode()));

            Assert.That(justA.GetOrElse(new object()), Is.SameAs(a));

            bool called = false;

            justA.GetOrElseGet(() =>
            {
                called = true;
                return(new object());
            });
            Assert.That(called, Is.False);
        }
Beispiel #2
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = mutable.GetHashCode();
         hashCode = hashCode * 397 ^ (name?.GetHashCode() ?? 0);
         hashCode = hashCode * 397 ^ (label?.GetHashCode() ?? 0);
         hashCode = hashCode * 397 ^ (_defaultValue?.GetHashCode() ?? 0);
         hashCode = hashCode * 397 ^ _typeConstraint.Map(tc => tc.Hash).DefaultTo(() => 0);
         hashCode = hashCode * 397 ^ reference.GetHashCode();
         hashCode = hashCode * 397 ^ capturing.GetHashCode();
         return(hashCode);
     }
 }