public void TestBaseTypeDynamicTransforms()
        {
            CommonTestInitialization();

            // public class Base0 { }
            Assert.Equal(_objectType, _base0Class.BaseType());
            Assert.False(_base0Class.ContainsDynamic());

            // public class Base1<T> { }
            Assert.Equal(_objectType, _base1Class.BaseType());
            Assert.False(_base1Class.ContainsDynamic());

            // public class Base2<T, U> { }
            Assert.Equal(_objectType, _base2Class.BaseType());
            Assert.False(_base2Class.ContainsDynamic());

            // public class Derived<T> : Outer<dynamic>.Inner<Outer<dynamic>.Inner<T[], dynamic>.InnerInner<int>[], dynamic>.InnerInner<dynamic> where T : Derived<T> { ... }
            Assert.False(_derivedClass.ContainsDynamic());
            Assert.True(_derivedClass.BaseType().ContainsDynamic());

            // Outer<dynamic>
            var outerClassOfDynamic = _outerClass.Construct(s_dynamicType);
            // Outer<dynamic>.Inner<T[], dynamic>
            var t        = _derivedClass.TypeParameters[0];
            var arrayOfT = ArrayTypeSymbol.CreateCSharpArray(_assembly, TypeWithAnnotations.Create(t));
            var innerClassOfTArrDynamic = outerClassOfDynamic.GetTypeMember("Inner").Construct(arrayOfT, s_dynamicType);
            // Outer<dynamic>.Inner<T[], dynamic>.InnerInner<int>[]
            var memberInnerInnerOfInt  = innerClassOfTArrDynamic.GetTypeMember("InnerInner").Construct(_intType);
            var arrayOfInnerInnerOfInt = ArrayTypeSymbol.CreateCSharpArray(_assembly, TypeWithAnnotations.Create(memberInnerInnerOfInt));
            // Outer<dynamic>.Inner<Outer<dynamic>.Inner<T[], dynamic>.InnerInner<int>[], dynamic>
            var memberComplicatedInner = outerClassOfDynamic.GetTypeMember("Inner").Construct(arrayOfInnerInnerOfInt, s_dynamicType);
            // Outer<dynamic>.Inner<Outer<dynamic>.Inner<T[], dynamic>.InnerInner<int>[], dynamic>.InnerInner<dynamic>
            var memberInnerInnerOfDynamic = memberComplicatedInner.GetTypeMember("InnerInner").Construct(s_dynamicType);

            Assert.Equal(memberInnerInnerOfDynamic, _derivedClass.BaseType());

            // public class Outer<T> : Base1<dynamic>
            Assert.False(_outerClass.ContainsDynamic());
            Assert.True(_outerClass.BaseType().ContainsDynamic());
            var base1OfDynamic = _base1Class.Construct(s_dynamicType);

            Assert.Equal(base1OfDynamic, _outerClass.BaseType());

            // public class Inner<U, V> : Base2<dynamic, V>
            Assert.False(_innerClass.ContainsDynamic());
            Assert.True(_innerClass.BaseType().ContainsDynamic());
            var base2OfDynamicV = _base2Class.Construct(s_dynamicType, _innerClass.TypeParameters[1]);

            Assert.Equal(base2OfDynamicV, _innerClass.BaseType());

            // public class InnerInner<W> : Base1<dynamic> { }
            Assert.False(_innerInnerClass.ContainsDynamic());
            Assert.True(_innerInnerClass.BaseType().ContainsDynamic());
            Assert.Equal(base1OfDynamic, _innerInnerClass.BaseType());

            // public class Outer2<T> : Base1<dynamic>
            Assert.False(_outer2Class.ContainsDynamic());
            Assert.True(_outer2Class.BaseType().ContainsDynamic());
            Assert.Equal(base1OfDynamic, _outer2Class.BaseType());

            // public class Inner2<U, V> : Base0
            Assert.False(_inner2Class.ContainsDynamic());
            Assert.False(_inner2Class.BaseType().ContainsDynamic());
            Assert.Equal(_base0Class, _inner2Class.BaseType());

            // public class InnerInner2<W> : Base0 { }
            Assert.False(_innerInner2Class.ContainsDynamic());
            Assert.False(_innerInner2Class.BaseType().ContainsDynamic());
            Assert.Equal(_base0Class, _innerInner2Class.BaseType());

            // public class Inner3<U>
            Assert.False(_inner3Class.ContainsDynamic());
        }
Exemple #2
0
        public void TestBaseTypeDynamicTransforms()
        {
            CommonTestInitialization();

            // public class Base0 { }
            Assert.Equal(objectType, base0Class.BaseType);
            Assert.False(base0Class.ContainsDynamic());

            // public class Base1<T> { }
            Assert.Equal(objectType, base1Class.BaseType);
            Assert.False(base1Class.ContainsDynamic());

            // public class Base2<T, U> { }
            Assert.Equal(objectType, base2Class.BaseType);
            Assert.False(base2Class.ContainsDynamic());

            // public class Derived<T> : Outer<dynamic>.Inner<Outer<dynamic>.Inner<T[], dynamic>.InnerInner<int>[], dynamic>.InnerInner<dynamic> where T : Derived<T> { ... }
            Assert.False(derivedClass.ContainsDynamic());
            Assert.True(derivedClass.BaseType.ContainsDynamic());

            // Outer<dynamic>
            var outerClassOfDynamic = outerClass.Construct(dynamicType);
            // Outer<dynamic>.Inner<T[], dynamic>
            var t        = derivedClass.TypeParameters[0];
            var arrayOfT = new ArrayTypeSymbol(assembly, t);
            var innerClassOfTArrDynamic = outerClassOfDynamic.GetTypeMember("Inner").Construct(arrayOfT, dynamicType);
            // Outer<dynamic>.Inner<T[], dynamic>.InnerInner<int>[]
            var memberInnerInnerOfInt  = innerClassOfTArrDynamic.GetTypeMember("InnerInner").Construct(intType);
            var arrayOfInnerInnerOfInt = new ArrayTypeSymbol(assembly, memberInnerInnerOfInt);
            // Outer<dynamic>.Inner<Outer<dynamic>.Inner<T[], dynamic>.InnerInner<int>[], dynamic>
            var memberComplicatedInner = outerClassOfDynamic.GetTypeMember("Inner").Construct(arrayOfInnerInnerOfInt, dynamicType);
            // Outer<dynamic>.Inner<Outer<dynamic>.Inner<T[], dynamic>.InnerInner<int>[], dynamic>.InnerInner<dynamic>
            var memberInnerInnerOfDynamic = memberComplicatedInner.GetTypeMember("InnerInner").Construct(dynamicType);

            Assert.Equal(memberInnerInnerOfDynamic, derivedClass.BaseType);

            // public class Outer<T> : Base1<dynamic>
            Assert.False(outerClass.ContainsDynamic());
            Assert.True(outerClass.BaseType.ContainsDynamic());
            var base1OfDynamic = base1Class.Construct(dynamicType);

            Assert.Equal(base1OfDynamic, outerClass.BaseType);

            // public class Inner<U, V> : Base2<dynamic, V>
            Assert.False(innerClass.ContainsDynamic());
            Assert.True(innerClass.BaseType.ContainsDynamic());
            var base2OfDynamicV = base2Class.Construct(dynamicType, innerClass.TypeParameters[1]);

            Assert.Equal(base2OfDynamicV, innerClass.BaseType);

            // public class InnerInner<W> : Base1<dynamic> { }
            Assert.False(innerInnerClass.ContainsDynamic());
            Assert.True(innerInnerClass.BaseType.ContainsDynamic());
            Assert.Equal(base1OfDynamic, innerInnerClass.BaseType);

            // public class Outer2<T> : Base1<dynamic>
            Assert.False(outer2Class.ContainsDynamic());
            Assert.True(outer2Class.BaseType.ContainsDynamic());
            Assert.Equal(base1OfDynamic, outer2Class.BaseType);

            // public class Inner2<U, V> : Base0
            Assert.False(inner2Class.ContainsDynamic());
            Assert.False(inner2Class.BaseType.ContainsDynamic());
            Assert.Equal(base0Class, inner2Class.BaseType);

            // public class InnerInner2<W> : Base0 { }
            Assert.False(innerInner2Class.ContainsDynamic());
            Assert.False(innerInner2Class.BaseType.ContainsDynamic());
            Assert.Equal(base0Class, innerInner2Class.BaseType);

            // public class Inner3<U>
            Assert.False(inner3Class.ContainsDynamic());
        }