예제 #1
0
        /// <summary>
        /// Gets if the two values are equal.
        /// </summary>
        /// <param name="other">
        /// The compared value.
        /// </param>
        /// <returns>
        /// returns <c>true</c> if
        ///
        /// The two values are both existing or missing
        /// and inner values are equal with the default comparer.
        /// </returns>
        public bool Equals(Opt <T> other)
        {
            if (!IsSome)
            {
                return(!other.IsSome);
            }

            return(other.IsSome && EqualityComparer <T> .Default.Equals(Value, other.Value));
        }
예제 #2
0
        public void SomeHasValue()
        {
            var some1 = Opt.Some(1);

            some1.IsSome
            .Is(true);
            some1.Value
            .Is(1);
        }
예제 #3
0
        public void NoneHasNoValue()
        {
            var none = Opt.None <int>();

            none.IsSome
            .Is(false);

            Assert.Throws <InvalidOperationException>(() =>
                                                      Opt.None <string>().Value
                                                      );
        }
예제 #4
0
        /// <summary>
        /// Compare the two values.
        ///
        /// <c>None</c>s are lesser than <c>Some</c>s.
        /// </summary>
        public int CompareTo(Opt <T> other)
        {
            if (!IsSome)
            {
                return(other.IsSome ? 0 : 1);
            }

            if (!other.IsSome)
            {
                return(-1);
            }

            return(Comparer <T> .Default.Compare(Value, other.Value));
        }
예제 #5
0
 public void ItMapsNoneToNestedSome()
 {
     Opt.AllowNull(Opt.None <int>())
     .Is(Opt.Some(Opt.None <int>()));
 }
예제 #6
0
 public void ItMapsNonnullDefaultToSome()
 {
     Opt.AllowNull(default(int))
     .Is(Opt.Some(0));
 }
예제 #7
0
 public void ItMapsNonnullToSome()
 {
     Opt.AllowNull("not null")
     .Is(Opt.Some("not null"));
 }
예제 #8
0
 public void ItMapsNullStructToNone()
 {
     Opt.AllowNull((int?)null)
     .Is(Opt.None <int>());
 }
예제 #9
0
 public void ItMapsNullReferenceToNone()
 {
     Opt.AllowNull((string)null)
     .Is(Opt.None <string>());
 }
예제 #10
0
 public void SomeRejectsNull()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           Opt.Some((string)null)
                                           );
 }
예제 #11
0
파일: Record.cs 프로젝트: vain0x/playground
 public Field(Opt <T> defaultValue, int index)
 {
     DefaultValue = defaultValue;
     Index        = index;
 }