コード例 #1
0
        public void EqualsTo_ShouldCompare(string src, bool equals)
        {
            Assembly asm = Compile(src, customConfig: comp => comp.WithOptions(((CSharpCompilationOptions)comp.Options).WithAllowUnsafe(true)));

            ITypeInfo
                a1 = MetadataTypeInfo.CreateFrom(asm.GetTypes().Single(t => t.Name.Contains("ClassA")).ListMethods().Single(m => m.Name == "Foo").GetParameters().Single().ParameterType),
                b1 = MetadataTypeInfo.CreateFrom(asm.GetTypes().Single(t => t.Name.Contains("ClassB")).ListMethods().Single(m => m.Name == "Foo").GetParameters().Single().ParameterType);

            CSharpCompilation compilation = CreateCompilation(src);

            var visitor = new FindAllTypesVisitor();

            visitor.VisitNamespace(compilation.GlobalNamespace);

            ITypeInfo
                a2 = SymbolTypeInfo.CreateFrom(visitor.AllTypeSymbols.Single(t => t.Name == "ClassA").ListMethods().Single(m => m.Name == "Foo").Parameters.Single().Type, compilation),
                b2 = SymbolTypeInfo.CreateFrom(visitor.AllTypeSymbols.Single(t => t.Name == "ClassB").ListMethods().Single(m => m.Name == "Foo").Parameters.Single().Type, compilation);

            Assert.That(a1.EqualsTo(b1), Is.EqualTo(equals));
            Assert.That(a2.EqualsTo(b2), Is.EqualTo(equals));
            Assert.That(a1.EqualsTo(b2), Is.EqualTo(equals));
            Assert.That(a2.EqualsTo(b1), Is.EqualTo(equals));
        }