Example #1
0
        private static void AssertGeneratedEmbeddedAttribute(
            AssemblySymbol assembly,
            string expectedTypeName
            )
        {
            var typeSymbol = assembly.GetTypeByMetadataName(expectedTypeName);

            Assert.NotNull(typeSymbol);
            Assert.Equal(Accessibility.Internal, typeSymbol.DeclaredAccessibility);

            var attributes = typeSymbol
                             .GetAttributes()
                             .OrderBy(attribute => attribute.AttributeClass.Name)
                             .ToArray();

            Assert.Equal(2, attributes.Length);

            Assert.Equal(
                WellKnownTypes.GetMetadataName(
                    WellKnownType.System_Runtime_CompilerServices_CompilerGeneratedAttribute
                    ),
                attributes[0].AttributeClass.ToDisplayString()
                );
            Assert.Equal(
                AttributeDescription.CodeAnalysisEmbeddedAttribute.FullName,
                attributes[1].AttributeClass.ToDisplayString()
                );
        }
Example #2
0
        private static void AssertNoIsByRefLikeAttributeExists(AssemblySymbol assembly)
        {
            var isByRefLikeAttributeTypeName = WellKnownTypes.GetMetadataName(
                WellKnownType.System_Runtime_CompilerServices_IsByRefLikeAttribute
                );

            Assert.Null(assembly.GetTypeByMetadataName(isByRefLikeAttributeTypeName));
        }
        private static string GetDebuggerDisplayString(AssemblySymbol assembly, int ordinal, int fieldCount)
        {
            NamedTypeSymbol anon;
            if (fieldCount == 0)
            {
                anon = assembly.GetTypeByMetadataName("<>f__AnonymousType0");
            }
            else
            {
                anon = assembly.GetTypeByMetadataName("<>f__AnonymousType" + ordinal + "`" + fieldCount);
            }

            var dd = anon.GetAttributes().Where(a => a.AttributeClass.Name == "DebuggerDisplayAttribute").Single();
            return (string)dd.ConstructorArguments.Single().Value;
        }
Example #4
0
            public Test01()
            {
                string source =
                    @"
using System.Diagnostics;

[assembly: DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
[module: DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]


[DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
class TestClass
{
    [DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
    public int testField;


    [DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
    public int TestProperty
    {
        [return: DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
        get
        {
            return testField;
        }
    }

    [return: DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
    [DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
    public T TestMethod<[DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )] T>
        ([DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )] T testParameter)
    {
        return testParameter;
    }
}";
                var compilation1 = CSharpCompilation.Create(
                    "C1",
                    new[] { Parse(source) },
                    new[] { OldMsCorLib },
                    TestOptions.ReleaseDll
                    );

                c1 = new CSharpCompilationReference(compilation1);

                var c1Assembly = compilation1.Assembly;

                var compilation2 = CSharpCompilation.Create(
                    "C2",
                    references: new MetadataReference[] { NewMsCorLib, c1 }
                    );

                c2 = new CSharpCompilationReference(compilation2);

                var c1AsmRef = compilation2.GetReferencedAssemblySymbol(c1);

                Assert.NotSame(c1Assembly, c1AsmRef);

                c1MscorLibAssemblyRef = compilation1.GetReferencedAssemblySymbol(OldMsCorLib);
                c2MscorlibAssemblyRef = compilation2.GetReferencedAssemblySymbol(NewMsCorLib);
                Assert.NotSame(c1MscorLibAssemblyRef, c2MscorlibAssemblyRef);

                oldMsCorLib_systemType = c1MscorLibAssemblyRef.GetTypeByMetadataName("System.Type");
                newMsCorLib_systemType = c2MscorlibAssemblyRef.GetTypeByMetadataName("System.Type");
                Assert.NotSame(oldMsCorLib_systemType, newMsCorLib_systemType);

                oldMsCorLib_debuggerTypeProxyAttributeType =
                    c1MscorLibAssemblyRef.GetTypeByMetadataName(
                        "System.Diagnostics.DebuggerTypeProxyAttribute"
                        );
                newMsCorLib_debuggerTypeProxyAttributeType =
                    c2MscorlibAssemblyRef.GetTypeByMetadataName(
                        "System.Diagnostics.DebuggerTypeProxyAttribute"
                        );
                Assert.NotSame(
                    oldMsCorLib_debuggerTypeProxyAttributeType,
                    newMsCorLib_debuggerTypeProxyAttributeType
                    );

                oldMsCorLib_debuggerTypeProxyAttributeCtor =
                    (MethodSymbol)oldMsCorLib_debuggerTypeProxyAttributeType
                    .GetMembers(".ctor")
                    .Single(
                        m =>
                        ((MethodSymbol)m).ParameterCount == 1 &&
                        TypeSymbol.Equals(
                            ((MethodSymbol)m).GetParameterType(0),
                            oldMsCorLib_systemType,
                            TypeCompareKind.ConsiderEverything2
                            )
                        );

                newMsCorLib_debuggerTypeProxyAttributeCtor =
                    (MethodSymbol)newMsCorLib_debuggerTypeProxyAttributeType
                    .GetMembers(".ctor")
                    .Single(
                        m =>
                        ((MethodSymbol)m).ParameterCount == 1 &&
                        TypeSymbol.Equals(
                            ((MethodSymbol)m).GetParameterType(0),
                            newMsCorLib_systemType,
                            TypeCompareKind.ConsiderEverything2
                            )
                        );

                Assert.NotSame(
                    oldMsCorLib_debuggerTypeProxyAttributeCtor,
                    newMsCorLib_debuggerTypeProxyAttributeCtor
                    );
            }
            public Test01()
            {
                string source = @"
using System.Diagnostics;

[assembly: DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
[module: DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]


[DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
class TestClass
{
    [DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
    public int testField;


    [DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
    public int TestProperty
    {
        [return: DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
        get
        {
            return testField;
        }
    }

    [return: DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
    [DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )]
    public T TestMethod<[DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )] T>
        ([DebuggerTypeProxyAttribute(typeof(System.Type), Target = typeof(int[]), TargetTypeName = ""IntArrayType"" )] T testParameter)
    {
        return testParameter;
    }
}";
                var compilation1 = CSharpCompilation.Create("C1", new[] { Parse(source) }, new[] { OldMsCorLib }, TestOptions.ReleaseDll);
                c1 = new CSharpCompilationReference(compilation1);

                var c1Assembly = compilation1.Assembly;

                var compilation2 = CSharpCompilation.Create("C2", references: new MetadataReference[] { NewMsCorLib, c1 });
                c2 = new CSharpCompilationReference(compilation2);

                var c1AsmRef = compilation2.GetReferencedAssemblySymbol(c1);
                Assert.NotSame(c1Assembly, c1AsmRef);

                c1MscorLibAssemblyRef = compilation1.GetReferencedAssemblySymbol(OldMsCorLib);
                c2MscorlibAssemblyRef = compilation2.GetReferencedAssemblySymbol(NewMsCorLib);
                Assert.NotSame(c1MscorLibAssemblyRef, c2MscorlibAssemblyRef);

                oldMsCorLib_systemType = c1MscorLibAssemblyRef.GetTypeByMetadataName("System.Type");
                newMsCorLib_systemType = c2MscorlibAssemblyRef.GetTypeByMetadataName("System.Type");
                Assert.NotSame(oldMsCorLib_systemType, newMsCorLib_systemType);

                oldMsCorLib_debuggerTypeProxyAttributeType = c1MscorLibAssemblyRef.GetTypeByMetadataName("System.Diagnostics.DebuggerTypeProxyAttribute");
                newMsCorLib_debuggerTypeProxyAttributeType = c2MscorlibAssemblyRef.GetTypeByMetadataName("System.Diagnostics.DebuggerTypeProxyAttribute");
                Assert.NotSame(oldMsCorLib_debuggerTypeProxyAttributeType, newMsCorLib_debuggerTypeProxyAttributeType);

                oldMsCorLib_debuggerTypeProxyAttributeCtor = (MethodSymbol)oldMsCorLib_debuggerTypeProxyAttributeType.GetMembers(".ctor").Single(
                    m => ((MethodSymbol)m).ParameterCount == 1 && ((MethodSymbol)m).ParameterTypes[0] == oldMsCorLib_systemType);

                newMsCorLib_debuggerTypeProxyAttributeCtor = (MethodSymbol)newMsCorLib_debuggerTypeProxyAttributeType.GetMembers(".ctor").Single(
                    m => ((MethodSymbol)m).ParameterCount == 1 && ((MethodSymbol)m).ParameterTypes[0] == newMsCorLib_systemType);

                Assert.NotSame(oldMsCorLib_debuggerTypeProxyAttributeCtor, newMsCorLib_debuggerTypeProxyAttributeCtor);
            }