Esempio n. 1
0
        private void TestBaseTypeResolutionHelper1(AssemblySymbol assembly)
        {
            var module0 = assembly.Modules[0];

            var sys         = module0.GlobalNamespace.GetMembers("System");
            var collections = ((NamespaceSymbol)sys[0]).GetMembers("Collections");
            var generic     = ((NamespaceSymbol)collections[0]).GetMembers("Generic");
            var dictionary  = ((NamespaceSymbol)generic[0]).GetMembers("Dictionary");
            var @base       = ((NamedTypeSymbol)dictionary[0]).BaseType();

            AssertBaseType(@base, "System.Object");
            Assert.Null(@base.BaseType());

            var concurrent = ((NamespaceSymbol)collections[0]).GetMembers("Concurrent");

            var orderablePartitioners = ((NamespaceSymbol)concurrent[0]).GetMembers(
                "OrderablePartitioner"
                );
            NamedTypeSymbol orderablePartitioner = null;

            foreach (var p in orderablePartitioners)
            {
                var t = p as NamedTypeSymbol;

                if ((object)t != null && t.Arity == 1)
                {
                    orderablePartitioner = t;
                    break;
                }
            }

            @base = orderablePartitioner.BaseType();

            AssertBaseType(@base, "System.Collections.Concurrent.Partitioner<TSource>");
            Assert.Same(
                ((NamedTypeSymbol)@base).TypeArguments()[0],
                orderablePartitioner.TypeParameters[0]
                );

            var             partitioners = ((NamespaceSymbol)concurrent[0]).GetMembers("Partitioner");
            NamedTypeSymbol partitioner  = null;

            foreach (var p in partitioners)
            {
                var t = p as NamedTypeSymbol;

                if ((object)t != null && t.Arity == 0)
                {
                    partitioner = t;
                    break;
                }
            }

            Assert.NotNull(partitioner);
        }
Esempio n. 2
0
        private static XElement LoadChildType(NamedTypeSymbol t)
        {
            XElement elem = new XElement("type");

            elem.Add(new XAttribute("name", t.Name));

            if (t.Arity > 0)
            {
                string typeParams = string.Empty;

                foreach (var param in t.TypeParameters)
                {
                    if (typeParams.Length > 0)
                    {
                        typeParams += ",";
                    }

                    typeParams += param.Name;
                }

                elem.Add(new XAttribute("Of", typeParams));
            }

            if ((object)t.BaseType() != null)
            {
                elem.Add(new XAttribute("base", t.BaseType().ToTestDisplayString()));
            }

            var fields = t.GetMembers()
                         .Where(m => m.Kind == SymbolKind.Field)
                         .OrderBy(f => f.Name)
                         .Cast <FieldSymbol>();

            elem.Add(from f in fields select LoadField(f));

            var childrenTypes = t.GetTypeMembers().OrderBy(c => c, new NameAndArityComparer());

            elem.Add(from c in childrenTypes select LoadChildType(c));

            return(elem);
        }
Esempio n. 3
0
        private void TestMissingTypeReferencesHelper2(AssemblySymbol[] assemblies, bool reflectionOnly = false)
        {
            var module1 = assemblies[0].Modules[0];
            var module2 = assemblies[1].Modules[0];

            var assembly2 = (MetadataOrSourceAssemblySymbol)assemblies[1];

            NamedTypeSymbol localTC = module1.GlobalNamespace.GetTypeMembers("TC1").Single();
            var             @base   = (MissingMetadataTypeSymbol)localTC.BaseType();

            Assert.Equal(SymbolKind.ErrorType, @base.Kind);
            Assert.False(@base.IsNamespace);
            Assert.True(@base.IsType);
            Assert.Equal("MissingC1", @base.Name);
            Assert.Equal(0, @base.Arity);
            Assert.Equal("MissingNS1.MissingC1[missing]", @base.ToTestDisplayString());
            Assert.Same(@base.ContainingAssembly, module2.ContainingAssembly);
            Assert.NotNull(@base.ContainingNamespace);
            Assert.Equal("MissingNS1", @base.ContainingNamespace.Name);
            Assert.Equal("", @base.ContainingNamespace.ContainingNamespace.Name);
            Assert.NotNull(@base.ContainingSymbol);
            Assert.NotNull(@base.ContainingAssembly);

            localTC = module1.GlobalNamespace.GetTypeMembers("TC2").Single();
            @base   = (MissingMetadataTypeSymbol)localTC.BaseType();
            Assert.Equal(SymbolKind.ErrorType, @base.Kind);
            Assert.False(@base.IsNamespace);
            Assert.True(@base.IsType);
            Assert.Equal("MissingC2", @base.Name);
            Assert.Equal(0, @base.Arity);
            Assert.Equal("MissingNS2.MissingNS3.MissingC2[missing]", @base.ToTestDisplayString());
            Assert.Same(@base.ContainingAssembly, module2.ContainingAssembly);
            Assert.Equal("MissingNS3", @base.ContainingNamespace.Name);
            Assert.Equal("MissingNS2", @base.ContainingNamespace.ContainingNamespace.Name);
            Assert.Equal("", @base.ContainingNamespace.ContainingNamespace.ContainingNamespace.Name);
            Assert.NotNull(@base.ContainingSymbol);
            Assert.NotNull(@base.ContainingAssembly);

            localTC = module1.GlobalNamespace.GetTypeMembers("TC3").Single();
            @base   = (MissingMetadataTypeSymbol)localTC.BaseType();
            Assert.Equal(SymbolKind.ErrorType, @base.Kind);
            Assert.False(@base.IsNamespace);
            Assert.True(@base.IsType);
            Assert.Equal("MissingC3", @base.Name);
            Assert.Equal(0, @base.Arity);
            Assert.Equal("NS4.MissingNS5.MissingC3[missing]", @base.ToTestDisplayString());
            Assert.Same(@base.ContainingAssembly, module2.ContainingAssembly);
            Assert.NotNull(@base.ContainingNamespace);
            Assert.NotNull(@base.ContainingSymbol);
            Assert.NotNull(@base.ContainingModule);

            localTC = module1.GlobalNamespace.GetTypeMembers("TC4").Single();
            var genericBase = localTC.BaseType();

            Assert.Equal(SymbolKind.ErrorType, genericBase.Kind);
            Assert.Equal("MissingC4<T1, S1>[missing]", genericBase.ToTestDisplayString());

            @base = (MissingMetadataTypeSymbol)genericBase.OriginalDefinition;
            Assert.Equal(SymbolKind.ErrorType, @base.Kind);
            Assert.False(@base.IsNamespace);
            Assert.True(@base.IsType);
            Assert.Equal("MissingC4", @base.Name);
            Assert.Equal(2, @base.Arity);
            Assert.Equal("MissingC4<,>[missing]", @base.ToTestDisplayString());
            Assert.Same(@base.ContainingAssembly, module2.ContainingAssembly);
            Assert.NotNull(@base.ContainingNamespace);
            Assert.NotNull(@base.ContainingSymbol);
            Assert.NotNull(@base.ContainingModule);
            var missingC4 = @base;

            localTC     = module1.GlobalNamespace.GetTypeMembers("TC5").Single();
            genericBase = localTC.BaseType();
            Assert.Equal("MissingC4<T1, S1>[missing].MissingC5<U1, V1, W1>[missing]", genericBase.ToTestDisplayString());

            @base = (MissingMetadataTypeSymbol)genericBase.OriginalDefinition;
            Assert.Equal(SymbolKind.ErrorType, @base.Kind);
            Assert.False(@base.IsNamespace);
            Assert.True(@base.IsType);
            Assert.Equal("MissingC5", @base.Name);
            Assert.Equal(3, @base.Arity);
            Assert.Equal("MissingC4<,>[missing].MissingC5<,,>[missing]", @base.ToTestDisplayString());
            Assert.Same(@base.ContainingAssembly, module2.ContainingAssembly);
            Assert.True(@base.ContainingNamespace.IsGlobalNamespace);
            Assert.Same(@base.ContainingSymbol, missingC4);

            var localC6 = module2.GlobalNamespace.GetTypeMembers("C6").Single();

            localTC = module1.GlobalNamespace.GetTypeMembers("TC6").Single();

            genericBase = localTC.BaseType();
            Assert.Equal("C6.MissingC7<U, V>[missing]", genericBase.ToTestDisplayString());
            Assert.Equal(SymbolKind.NamedType, genericBase.ContainingSymbol.Kind);

            @base = (MissingMetadataTypeSymbol)genericBase.OriginalDefinition;
            Assert.Equal(SymbolKind.ErrorType, @base.Kind);
            Assert.False(@base.IsNamespace);
            Assert.True(@base.IsType);
            Assert.Equal("MissingC7", @base.Name);
            Assert.Equal(2, @base.Arity);
            Assert.Equal("C6.MissingC7<,>[missing]", @base.ToTestDisplayString());
            Assert.Same(@base.ContainingAssembly, module2.ContainingAssembly);
            Assert.Same(@base.ContainingSymbol, localC6);
            Assert.Same(@base.ContainingNamespace, localC6.ContainingNamespace);

            var missingC7 = @base;

            localTC     = module1.GlobalNamespace.GetTypeMembers("TC7").Single();
            genericBase = localTC.BaseType();
            Assert.Equal("C6.MissingC7<U, V>[missing].MissingC8[missing]", genericBase.ToTestDisplayString());
            Assert.Equal(SymbolKind.ErrorType, genericBase.ContainingSymbol.Kind);

            @base = (MissingMetadataTypeSymbol)genericBase.OriginalDefinition;
            Assert.Equal(SymbolKind.ErrorType, @base.Kind);
            Assert.False(@base.IsNamespace);
            Assert.True(@base.IsType);
            Assert.Equal("MissingC8", @base.Name);
            Assert.Equal(0, @base.Arity);
            Assert.Equal("C6.MissingC7<,>[missing].MissingC8[missing]", @base.ToTestDisplayString());
            Assert.Same(@base.ContainingAssembly, module2.ContainingAssembly);
            if (!reflectionOnly)
            {
                Assert.Same(@base.ContainingSymbol, missingC7);
            }
            Assert.Equal(missingC7.ToTestDisplayString(), @base.ContainingSymbol.ToTestDisplayString());
            Assert.Same(@base.ContainingNamespace, localC6.ContainingNamespace);

            var missingC8 = @base;

            localTC     = module1.GlobalNamespace.GetTypeMembers("TC8").Single();
            genericBase = localTC.BaseType();
            Assert.Equal("C6.MissingC7<U, V>[missing].MissingC8[missing].MissingC9[missing]", genericBase.ToTestDisplayString());
            Assert.Equal(SymbolKind.ErrorType, genericBase.ContainingSymbol.Kind);

            @base = (MissingMetadataTypeSymbol)genericBase.OriginalDefinition;
            Assert.Equal(SymbolKind.ErrorType, @base.Kind);
            Assert.False(@base.IsNamespace);
            Assert.True(@base.IsType);
            Assert.Equal("MissingC9", @base.Name);
            Assert.Equal(0, @base.Arity);
            Assert.Equal("C6.MissingC7<,>[missing].MissingC8[missing].MissingC9[missing]", @base.ToTestDisplayString());
            Assert.Same(@base.ContainingAssembly, module2.ContainingAssembly);
            if (!reflectionOnly)
            {
                Assert.Same(@base.ContainingSymbol, missingC8);
            }
            Assert.Equal(missingC8.ToTestDisplayString(), @base.ContainingSymbol.ToTestDisplayString());
            Assert.Same(@base.ContainingNamespace, localC6.ContainingNamespace);

            Assert.IsAssignableFrom <MissingMetadataTypeSymbol>(assembly2.CachedTypeByEmittedName("MissingNS1.MissingC1"));
            Assert.IsAssignableFrom <MissingMetadataTypeSymbol>(assembly2.CachedTypeByEmittedName("MissingNS2.MissingNS3.MissingC2"));
            Assert.IsAssignableFrom <MissingMetadataTypeSymbol>(assembly2.CachedTypeByEmittedName("NS4.MissingNS5.MissingC3"));
            Assert.IsAssignableFrom <MissingMetadataTypeSymbol>(assembly2.CachedTypeByEmittedName("MissingC4`2"));
        }
Esempio n. 4
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(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());
        }