Exemplo n.º 1
0
        public void ToDerivedOnBaseDoesNotReturnDerivedInstance()
        {
            A c1AsA  = C1.Create();
            B result = c1AsA.ToB();

            Assert.NotSame(c1AsA, result);
            Assert.IsType <B>(result);            // should not retain C1 as its type
        }
Exemplo n.º 2
0
        public void ToBaseType()
        {
            C1 c1 = C1.Create(1, 2, 3);
            A  a  = c1.ToA();

            Assert.IsType(typeof(A), a);             // should not be a derived type.
            Assert.Equal(1, a.Field1);
        }
Exemplo n.º 3
0
        public void ToSiblingType()
        {
            C1 c1 = C1.Create(1, 2, 3);
            C2 c2 = c1.ToC2();

            Assert.Equal(1, c2.Field1);
            Assert.Equal(2, c2.Field2);
            Assert.Equal(0, c2.Field3);             // different field between types

            c2 = c1.ToC2(4);
            Assert.Equal(1, c2.Field1);
            Assert.Equal(2, c2.Field2);
            Assert.Equal(4, c2.Field3);
        }
Exemplo n.º 4
0
        public virtual C1 ToC1(
            ImmutableObjectGraph.Optional <System.Int32> field3 = default(ImmutableObjectGraph.Optional <System.Int32>))
        {
            C1 that = this as C1;

            if (that != null && this.GetType().IsEquivalentTo(typeof(C1)))
            {
                if ((!field3.IsDefined || field3.Value == that.Field3))
                {
                    return(that);
                }
            }

            return(C1.Create(
                       field1: this.Field1,
                       field2: this.Field2,
                       field3: field3));
        }