当前位置: 首页>>代码示例>>C#>>正文


C# CSharpCompilationReference类代码示例

本文整理汇总了C#中CSharpCompilationReference的典型用法代码示例。如果您正苦于以下问题:C# CSharpCompilationReference类的具体用法?C# CSharpCompilationReference怎么用?C# CSharpCompilationReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CSharpCompilationReference类属于命名空间,在下文中一共展示了CSharpCompilationReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestCompilationReferenceLocation

        public void TestCompilationReferenceLocation()
        {
            var source = @"public class C { }";

            var libRef = new CSharpCompilationReference(CreateCompilationWithMscorlib(Parse(source, "file1.cs"), assemblyName: "Metadata"));
            var comp = CreateCompilationWithMscorlib(Parse(source, "file2.cs"), new[] { libRef }, assemblyName: "Source");

            var sourceAssembly = comp.SourceAssembly;
            var referencedAssembly = (AssemblySymbol)comp.GetAssemblyOrModuleSymbol(libRef);

            var sourceType = sourceAssembly.GlobalNamespace.GetMember<NamedTypeSymbol>("C");
            var referencedType = referencedAssembly.GlobalNamespace.GetMember<NamedTypeSymbol>("C");
            var distinguisher = new SymbolDistinguisher(comp, sourceType, referencedType);
            Assert.Equal("C [file2.cs(1)]", distinguisher.First.ToString());
            Assert.Equal("C [file1.cs(1)]", distinguisher.Second.ToString());
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:16,代码来源:SymbolDistinguisherTests.cs

示例2: PlatformMismatch_07

        public void PlatformMismatch_07()
        {
            string refSource = @"
public interface ITestPlatform
{}
";
            var refCompilation = CreateCompilation(refSource, compOptions: TestOptions.Dll.WithPlatform(Platform.Itanium).WithRuntimeMetadataVersion("v4.0.31019"), assemblyName: "PlatformMismatch");

            refCompilation.VerifyEmitDiagnostics();
            var compRef = new CSharpCompilationReference(refCompilation);
            var imageRef = refCompilation.EmitToImageReference();

            string useSource = @"
public interface IUsePlatform
{
    ITestPlatform M();
}
";

            var useCompilation = CreateCompilation(useSource,
                new MetadataReference[] { compRef },
                compOptions: TestOptions.Dll.WithPlatform(Platform.Itanium).WithRuntimeMetadataVersion("v4.0.31019"));

            useCompilation.VerifyEmitDiagnostics();

            useCompilation = CreateCompilation(useSource,
                new MetadataReference[] { imageRef },
                compOptions: TestOptions.Dll.WithPlatform(Platform.Itanium).WithRuntimeMetadataVersion("v4.0.31019"));

            useCompilation.VerifyEmitDiagnostics();

            useCompilation = CreateCompilation(useSource,
                new MetadataReference[] { compRef },
                compOptions: TestOptions.NetModule.WithPlatform(Platform.Itanium).WithRuntimeMetadataVersion("v4.0.31019"));

            useCompilation.VerifyEmitDiagnostics();

            useCompilation = CreateCompilation(useSource,
                new MetadataReference[] { imageRef },
                compOptions: TestOptions.NetModule.WithPlatform(Platform.Itanium).WithRuntimeMetadataVersion("v4.0.31019"));

            useCompilation.VerifyEmitDiagnostics();
        }
开发者ID:riversky,项目名称:roslyn,代码行数:43,代码来源:CompilationEmitTests.cs

示例3: TestImplicitIndexerImplementation

        public void TestImplicitIndexerImplementation()
        {
            var text1 = @"
public interface BaseInterface1
{
    int this[int x] { get; }
}

public interface BaseInterface2
{
    int this[int x] { get; }
}
";
            var text2 = @"
public interface Interface : BaseInterface1, BaseInterface2
{
    int this[int x, int y] { get; }
}
";
            var text3 = @"
class Class : Interface
{
    public int this[int x] { get { return 0; } }
    public int this[int x, int y] { get { return 0; } }
}
";

            var comp1 = CreateCompilationWithMscorlib(text1);
            var comp1ref = new CSharpCompilationReference(comp1);
            var refs = new System.Collections.Generic.List<MetadataReference>() { comp1ref };

            var comp2 = CreateCompilationWithMscorlib(text2, references: refs, assemblyName: "Test2");
            var comp2ref = new CSharpCompilationReference(comp2);

            refs.Add(comp2ref);
            var comp = CreateCompilationWithMscorlib(text3, refs, assemblyName: "Test3");

            var global = comp.GlobalNamespace;

            var baseInterface1 = (NamedTypeSymbol)global.GetMembers("BaseInterface1").Single();
            var baseInterface1Indexer = baseInterface1.Indexers.Single();

            var baseInterface2 = (NamedTypeSymbol)global.GetMembers("BaseInterface2").Single();
            var baseInterface2Indexer = baseInterface2.Indexers.Single();

            var @interface = (NamedTypeSymbol)global.GetMembers("Interface").Single();
            var interfaceIndexer = @interface.Indexers.Single();

            var @class = (NamedTypeSymbol)global.GetMembers("Class").Single();
            var classImplicitImplementation = @class.Indexers.Where(p => p.Parameters.Length == 2).Single();
            var classImplicitImplementationBase = @class.Indexers.Where(p => p.Parameters.Length == 1).Single();

            var implementingIndexer = @class.FindImplementationForInterfaceMember(interfaceIndexer);
            Assert.Same(classImplicitImplementation, implementingIndexer);

            var implementingIndexerBase1 = @class.FindImplementationForInterfaceMember(baseInterface1Indexer);
            Assert.Same(classImplicitImplementationBase, implementingIndexerBase1);

            var implementingIndexerBase2 = @class.FindImplementationForInterfaceMember(baseInterface2Indexer);
            Assert.Same(classImplicitImplementationBase, implementingIndexerBase2);
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:61,代码来源:InterfaceImplementationTests.cs

示例4: NoBridgeMethodForVirtualImplementation

        public void NoBridgeMethodForVirtualImplementation()
        {
            var source1 = @"
public interface I
{
    void Virtual();
    void NonVirtual();
}

public class B
{
    public virtual void Virtual() { }
    public void NonVirtual() { }
}
";

            var source2 = @"
class D : B, I
{
}
";
            var comp1 = CreateCompilationWithMscorlib(source1, options: TestOptions.ReleaseDll, assemblyName: "asm1");
            comp1.VerifyDiagnostics();
            var ref1 = new CSharpCompilationReference(comp1);

            var comp2 = CreateCompilationWithMscorlib(source2, new[] { ref1 }, options: TestOptions.ReleaseDll, assemblyName: "asm2");
            comp2.VerifyDiagnostics();

            var derivedType = comp2.GlobalNamespace.GetMember<SourceNamedTypeSymbol>("D");
            var bridgeMethod = derivedType.GetSynthesizedExplicitImplementations(CancellationToken.None).Single();
            Assert.Equal("NonVirtual", bridgeMethod.ImplementingMethod.Name);
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:32,代码来源:InterfaceImplementationTests.cs

示例5: NameCollisionWithAddedModule_03

        public void NameCollisionWithAddedModule_03()
        {
            var forwardedTypesSource =
@"
public class CF1
{}

namespace ns
{
    public class CF2
    {
    }
}

public class CF3<T>
{}
";

            var forwardedTypes1 = CreateCompilationWithMscorlib(forwardedTypesSource, options: TestOptions.ReleaseDll, assemblyName: "ForwardedTypes1");
            var forwardedTypes1Ref = new CSharpCompilationReference(forwardedTypes1);

            var forwardedTypes2 = CreateCompilationWithMscorlib(forwardedTypesSource, options: TestOptions.ReleaseDll, assemblyName: "ForwardedTypes2");
            var forwardedTypes2Ref = new CSharpCompilationReference(forwardedTypes2);

            var forwardedTypesModRef = CreateCompilationWithMscorlib(forwardedTypesSource,
                                                                options: TestOptions.ReleaseModule,
                                                                assemblyName: "forwardedTypesMod").
                                       EmitToImageReference();

            var modSource =
@"
[assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(CF1))]
[assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(ns.CF2))]
";

            var module1_FT1_Ref = CreateCompilationWithMscorlib(modSource,
                                                                options: TestOptions.ReleaseModule,
                                                                assemblyName: "module1_FT1",
                                                                references: new MetadataReference[] { forwardedTypes1Ref }).
                                  EmitToImageReference();

            var module2_FT1_Ref = CreateCompilationWithMscorlib(modSource,
                                                                options: TestOptions.ReleaseModule,
                                                                assemblyName: "module2_FT1",
                                                                references: new MetadataReference[] { forwardedTypes1Ref }).
                                  EmitToImageReference();

            var module3_FT2_Ref = CreateCompilationWithMscorlib(modSource,
                                                                options: TestOptions.ReleaseModule,
                                                                assemblyName: "module3_FT2",
                                                                references: new MetadataReference[] { forwardedTypes2Ref }).
                                  EmitToImageReference();

            var module4_Ref = CreateCompilationWithMscorlib("[assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(CF3<int>))]",
                                                                options: TestOptions.ReleaseModule,
                                                                assemblyName: "module4_FT1",
                                                                references: new MetadataReference[] { forwardedTypes1Ref }).
                                  EmitToImageReference();

            var compilation = CreateCompilationWithMscorlib(forwardedTypesSource,
                new List<MetadataReference>()
                {
                    module1_FT1_Ref,
                    forwardedTypes1Ref
                }, TestOptions.ReleaseDll);

            compilation.VerifyEmitDiagnostics(
                // error CS8006: Forwarded type 'ns.CF2' conflicts with type declared in primary module of this assembly.
                Diagnostic(ErrorCode.ERR_ForwardedTypeConflictsWithDeclaration).WithArguments("ns.CF2"),
                // error CS8006: Forwarded type 'CF1' conflicts with type declared in primary module of this assembly.
                Diagnostic(ErrorCode.ERR_ForwardedTypeConflictsWithDeclaration).WithArguments("CF1"));

            compilation = CreateCompilationWithMscorlib(modSource,
                new List<MetadataReference>()
                {
                    module1_FT1_Ref,
                    forwardedTypes1Ref
                }, TestOptions.ReleaseDll);

            // Exported types in .Net modules cause PEVerify to fail.
            CompileAndVerify(compilation, verify: false).VerifyDiagnostics();

            compilation = CreateCompilationWithMscorlib("[assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(CF3<byte>))]",
                new List<MetadataReference>()
                {
                    module4_Ref,
                    forwardedTypes1Ref
                }, TestOptions.ReleaseDll);

            CompileAndVerify(compilation, verify: false).VerifyDiagnostics();

            compilation = CreateCompilationWithMscorlib(modSource,
                new List<MetadataReference>()
                {
                    module1_FT1_Ref,
                    forwardedTypes2Ref,
                    new CSharpCompilationReference(forwardedTypes1, aliases: ImmutableArray.Create("FT1"))
                }, TestOptions.ReleaseDll);

            compilation.VerifyEmitDiagnostics(
//.........这里部分代码省略.........
开发者ID:nevinclement,项目名称:roslyn,代码行数:101,代码来源:SymbolErrorTests.cs

示例6: CS1757ERR_InteropStructContainsMethods

        public void CS1757ERR_InteropStructContainsMethods()
        {
            var textdll = @"using System;
using System.Runtime.InteropServices;
[assembly: ImportedFromTypeLib(""NoPiaTestLib"")]
[assembly: Guid(""A7721B07-2448-447A-BA36-64682CBEF136"")]
namespace NS
{
    public struct MyStruct
    {
        private int _age;
        public string Name;
    }
}
";
            var text = @"public class Test
{
    public static void Main()
    {
        NS.MyStruct S = new NS.MyStruct();
        System.Console.Write(S);
    }
}
";
            var comp = CreateCompilationWithMscorlib(textdll);
            var ref1 = new CSharpCompilationReference(comp, embedInteropTypes: true);
            var comp1 = CreateCompilationWithMscorlib(text, new[] { ref1 });
            comp1.VerifyEmitDiagnostics(
                // (5,24): error CS1757: Embedded interop struct 'NS.MyStruct' can contain only public instance fields.
                //         NS.MyStruct S = new NS.MyStruct();
                Diagnostic(ErrorCode.ERR_InteropStructContainsMethods, "new NS.MyStruct()").WithArguments("NS.MyStruct"));
        }
开发者ID:nevinclement,项目名称:roslyn,代码行数:32,代码来源:SymbolErrorTests.cs

示例7: CS1754ERR_NoPIANestedType

        public void CS1754ERR_NoPIANestedType()
        {
            var textdll = @"using System;
using System.Runtime.InteropServices;
[assembly: ImportedFromTypeLib(""NoPiaTestLib"")]
[assembly: Guid(""A7721B07-2448-447A-BA36-64682CBEF136"")]
namespace NS
{
    public struct MyClass
    {
        public struct NestedClass
        {
            public string Name;
        }
    }
}
";
            var text = @"public class Test
{
    public static void Main()
    {
        var S = new NS.MyClass.NestedClass();
        System.Console.Write(S);
    }
}
";
            var comp = CreateCompilationWithMscorlib(textdll);
            var ref1 = new CSharpCompilationReference(comp, embedInteropTypes: true);
            CreateCompilationWithMscorlib(text, new[] { ref1 }).VerifyDiagnostics(
               Diagnostic(ErrorCode.ERR_NoPIANestedType, "NestedClass").WithArguments("NS.MyClass.NestedClass"));
        }
开发者ID:nevinclement,项目名称:roslyn,代码行数:31,代码来源:SymbolErrorTests.cs

示例8: CS0730ERR_ForwardedTypeIsNested

        public void CS0730ERR_ForwardedTypeIsNested()
        {
            var text1 = @"public class C
{
    public class CC
    {
    }
}
";
            var text2 = @"
using System.Runtime.CompilerServices;

[assembly: TypeForwardedTo(typeof(C.CC))]";

            var comp1 = CreateCompilationWithMscorlib(text1);
            var compRef1 = new CSharpCompilationReference(comp1);

            var comp2 = CreateCompilationWithMscorlib(text2, new MetadataReference[] { compRef1 });
            comp2.VerifyDiagnostics(
                // (4,12): error CS0730: Cannot forward type 'C.CC' because it is a nested type of 'C'
                // [assembly: TypeForwardedTo(typeof(C.CC))]
                Diagnostic(ErrorCode.ERR_ForwardedTypeIsNested, "TypeForwardedTo(typeof(C.CC))").WithArguments("C.CC", "C"));
        }
开发者ID:nevinclement,项目名称:roslyn,代码行数:23,代码来源:SymbolErrorTests.cs

示例9: TestCyclicConstantEvalAcrossCompilations

        public void TestCyclicConstantEvalAcrossCompilations()
        {
            var source1 =
@"public class A
{
    public const string A1 = B.B1;
}
public class B
{
    public const string B1 = A.A1;
}
public class C
{
    public const string C1 = B.B1;
}";
            var source2 =
@"public class D
{
    public const string D1 = D1;
}";
            var source3 =
@"public class E
{
    public const string E1 = F.F1;
}
public class F
{
    public const string F1 = C.C1;
}";
            var source4 =
@"public class G
{
    public const string G1 = F.F1 + D.D1;
}";
            var compilation1 = CreateCompilationWithMscorlib(source1);
            var reference1 = new CSharpCompilationReference(compilation1);
            var compilation2 = CreateCompilationWithMscorlib(source2);
            var reference2 = new CSharpCompilationReference(compilation2);
            var compilation3 = CreateCompilationWithMscorlib(source3, new MetadataReference[] { reference1 });
            var reference3 = new CSharpCompilationReference(compilation3);
            var compilation4 = CreateCompilationWithMscorlib(source4, new MetadataReference[] { reference2, reference3 });
            compilation4.VerifyDiagnostics();
            compilation3.VerifyDiagnostics();
            compilation2.VerifyDiagnostics(
                // (3,25): error CS0110: The evaluation of the constant value for 'D.D1' involves a circular definition
                //     public const string D1 = D1;
                Diagnostic(ErrorCode.ERR_CircConstValue, "D1").WithArguments("D.D1").WithLocation(3, 25));
            compilation1.VerifyDiagnostics(
                // (3,25): error CS0110: The evaluation of the constant value for 'A.A1' involves a circular definition
                //     public const string A1 = B.B1;
                Diagnostic(ErrorCode.ERR_CircConstValue, "A1").WithArguments("A.A1").WithLocation(3, 25));
        }
开发者ID:jeffanders,项目名称:roslyn,代码行数:52,代码来源:ConstantTests.cs

示例10: PortableLibrary

        public void PortableLibrary()
        {
            var plSource = @"public class C {}";
            var pl = CreateCompilation(plSource, new[] { MscorlibPP7Ref, SystemRuntimePP7Ref });
            var r1 = new CSharpCompilationReference(pl);

            var mainSource = @"public class D : C { }";

            // w/o facades:
            var main = CreateCompilation(mainSource, new MetadataReference[] { r1, MscorlibFacadeRef }, options: TestOptions.ReleaseDll);
            main.VerifyDiagnostics(
                // (1,18): error CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
                Diagnostic(ErrorCode.ERR_NoTypeDef, "C").WithArguments("System.Object", "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"));

            // facade specified:
            main = CreateCompilation(mainSource, new MetadataReference[] { r1, MscorlibFacadeRef, SystemRuntimeFacadeRef });
            main.VerifyDiagnostics();
        }
开发者ID:bakitorunoglu,项目名称:roslyn,代码行数:18,代码来源:ReferenceManagerTests.cs

示例11: TypeCrossComps

        public void TypeCrossComps()
        {
            #region "Interface Impl"
            var text = @"
    public interface IFoo  {
        void M0();
    }
";

            var text1 = @"
    public class Foo : IFoo  {
        public void M0() {}
    }
";
            var comp1 = CreateCompilationWithMscorlib(text);
            var compRef1 = new CSharpCompilationReference(comp1);
            var comp = CreateCompilationWithMscorlib(text1, references: new List<MetadataReference> { compRef1 }, assemblyName: "Comp2");

            Assert.Equal(0, comp.GetDiagnostics().Count());
            #endregion

            #region "Interface Inherit"
            text = @"
    public interface IFoo  {
        void M0();
    }
";

            text1 = @"
    public interface IBar : IFoo  {
        void M1();
    }
";
            comp1 = CreateCompilationWithMscorlib(text);
            compRef1 = new CSharpCompilationReference(comp1);
            comp = CreateCompilationWithMscorlib(text1, references: new List<MetadataReference> { compRef1 }, assemblyName: "Comp2");

            Assert.Equal(0, comp.GetDiagnostics().Count());
            #endregion

            #region "Class Inherit"
            text = @"
public class A { 
    void M0() {}
}
";

            text1 = @"
public class B : A { 
    void M1() {}
}
";
            comp1 = CreateCompilationWithMscorlib(text);
            compRef1 = new CSharpCompilationReference(comp1);
            comp = CreateCompilationWithMscorlib(text1, references: new List<MetadataReference> { compRef1 }, assemblyName: "Comp2");

            Assert.Equal(0, comp.GetDiagnostics().Count());
            #endregion

            #region "Partial"
            text = @"
public partial interface IBar {
    void M0();
}

public partial class A { }
";

            text1 = @"
public partial interface IBar {
    void M1();
}

public partial class A { }
";
            comp1 = CreateCompilationWithMscorlib(text);
            compRef1 = new CSharpCompilationReference(comp1);
            comp = CreateCompilationWithMscorlib(text1, references: new List<MetadataReference> { compRef1 }, assemblyName: "Comp2");

            Assert.Equal(0, comp.GetDiagnostics().Count());
            #endregion
        }
开发者ID:hughgao,项目名称:roslyn,代码行数:82,代码来源:TypeTests.cs

示例12: InheritedTypesCrossComps

        public void InheritedTypesCrossComps()
        {
            var text = @"namespace MT {
    public interface IFoo { void Foo(); }
    public interface IFoo<T, R> { R Foo(T t); }
    public interface IEmpty { }
}
";
            var text1 = @"namespace MT {
    public interface IBar<T> : IFoo, IEmpty { void Bar(T t); }
}
";
            var text2 = @"namespace NS {
    using MT;
    public class A<T> : IFoo<T, string>, IBar<T>, IFoo {
        void IFoo.Foo() { }
        public string Foo(T t) { return null; }
        void IBar<T>.Bar(T t) { }
    }

    public class B : A<ulong> {}
}
";
            var text3 = @"namespace NS {
    public class C : B {}
}
";
            var comp1 = CreateCompilationWithMscorlib(text);
            var compRef1 = new CSharpCompilationReference(comp1);

            var comp2 = CreateCompilationWithMscorlib(new string[] { text1, text2 }, assemblyName: "Test1",
                            references: new List<MetadataReference> { compRef1 });
            var compRef2 = new CSharpCompilationReference(comp2);

            var comp = CreateCompilationWithMscorlib(text3, assemblyName: "Test2",
                            references: new List<MetadataReference> { compRef2, compRef1 });

            Assert.Equal(0, comp1.GetDiagnostics().Count());
            Assert.Equal(0, comp2.GetDiagnostics().Count());
            Assert.Equal(0, comp.GetDiagnostics().Count());

            var global = comp.GlobalNamespace;
            var ns = global.GetMembers("NS").Single() as NamespaceSymbol;

            var type1 = ns.GetTypeMembers("C", 0).SingleOrDefault() as NamedTypeSymbol;
            Assert.Equal(0, type1.Interfaces.Length);
            //
            Assert.Equal(4, type1.AllInterfaces.Length);
            var sorted = (from i in type1.AllInterfaces
                          orderby i.Name
                          select i).ToArray();
            var i1 = sorted[0] as NamedTypeSymbol;
            var i2 = sorted[1] as NamedTypeSymbol;
            var i3 = sorted[2] as NamedTypeSymbol;
            var i4 = sorted[3] as NamedTypeSymbol;
            Assert.Equal("MT.IBar<System.UInt64>", i1.ToTestDisplayString());
            Assert.Equal(1, i1.Arity);
            Assert.Equal("MT.IEmpty", i2.ToTestDisplayString());
            Assert.Equal(0, i2.Arity);
            Assert.Equal("MT.IFoo<System.UInt64, System.String>", i3.ToTestDisplayString());
            Assert.Equal(2, i3.Arity);
            Assert.Equal("MT.IFoo", i4.ToTestDisplayString());
            Assert.Equal(0, i4.Arity);

            Assert.Equal("B", type1.BaseType.Name);
            // B
            var type2 = type1.BaseType as NamedTypeSymbol;
            //
            Assert.Equal(4, type2.AllInterfaces.Length);
            Assert.NotNull(type2.BaseType);
            // A<ulong>
            var type3 = type2.BaseType as NamedTypeSymbol;
            // T1?
            Assert.Equal("NS.A<System.UInt64>", type3.ToTestDisplayString());
            Assert.Equal(3, type3.Interfaces.Length);
            Assert.Equal(4, type3.AllInterfaces.Length);

            var type33 = ns.GetTypeMembers("A", 1).SingleOrDefault() as NamedTypeSymbol;
            Assert.Equal("NS.A<T>", type33.ToTestDisplayString());
            Assert.Equal(3, type33.Interfaces.Length);
            Assert.Equal(4, type33.AllInterfaces.Length);
        }
开发者ID:hughgao,项目名称:roslyn,代码行数:82,代码来源:TypeTests.cs

示例13: MissingImplementedInterface

        public void MissingImplementedInterface()
        {
            var lib1 = CreateCompilationWithMscorlib(@"
namespace ErrorTest
{
    public interface I1
    {
        void M1();
    }

    public class C9<T> where T : I1
    { }
}
", compOptions: TestOptions.Dll, assemblyName: "MissingImplementedInterface1");

            var lib1Ref = new CSharpCompilationReference(lib1);

            var lib2 = CreateCompilationWithMscorlib(@"
namespace ErrorTest
{
    public interface I2
        : I1
    {}

    public class C12
        : I2
    {
        private void M1() //Implements I1.M1
        {}

        void I1.M1()
        {
        }
    }
}
", new[] { lib1Ref }, TestOptions.Dll, assemblyName: "MissingImplementedInterface2");

            var lib2Ref = new CSharpCompilationReference(lib2);

            var lib3 = CreateCompilationWithMscorlib(@"
namespace ErrorTest
{
    public class C4
        : I2
    {
        private void M1() //Implements I1.M1
        {}

        void I1.M1()
        {
        }
    }

    public interface I5
        : I2
    {}

    public class C13
        : C12
    { }
}
", new[] { lib1Ref, lib2Ref }, TestOptions.Dll, assemblyName: "MissingImplementedInterface3");

            var lib3Ref = new CSharpCompilationReference(lib3);

            var lib4Def = @"
namespace ErrorTest
{
    class Test
    {
        void _Test(C4 y)
        {
            I1 x = y;
        }
    }

    public class C6 : I5
    {
        void I1.M1() 
        {}
    }

    public class C7 : C4
    {}

    class Test2
    {
        void _Test2(I5 x, C4 y)
        {
            x.M1();
            y.M1();
        }
    }

    class Test3<T> where T : C4
    {
        void Test(T y3)
        {
            I1 x = y3;
            y3.M1();
//.........这里部分代码省略.........
开发者ID:nagyist,项目名称:roslyn,代码行数:101,代码来源:BadSymbolReference.cs

示例14: MissingTypeInTypeArgumentsOfImplementedInterface

        public void MissingTypeInTypeArgumentsOfImplementedInterface()
        {
            var lib1 = CreateCompilationWithMscorlib(@"
namespace ErrorTest
{
    public interface I1<out T1>
    {}

    public interface I2
    {}

    public interface I6<in T1>
    {}

    public class C10<T> where T : I1<I2>
    {}
}", compOptions: TestOptions.Dll, assemblyName: "MissingTypeInTypeArgumentsOfImplementedInterface1");

            var lib1Ref = new CSharpCompilationReference(lib1);

            var lib2 = CreateCompilationWithMscorlib(@"
namespace ErrorTest
{
    public interface I3 : I2
    {}

}", new[] { lib1Ref }, TestOptions.Dll, assemblyName: "MissingTypeInTypeArgumentsOfImplementedInterface2");

            var lib2Ref = new CSharpCompilationReference(lib2);

            var lib3 = CreateCompilationWithMscorlib(@"
namespace ErrorTest
{
    public class C4 : I1<I3>
    {}

    public interface I5 : I1<I3>
    {}

    public class C8<T> where T : I6<I3>
    {}
}", new[] { lib1Ref, lib2Ref }, TestOptions.Dll, assemblyName: "MissingTypeInTypeArgumentsOfImplementedInterface3");

            var lib3Ref = new CSharpCompilationReference(lib3);

            var lib4Def = @"
namespace ErrorTest
{
    class Test
    {
        void _Test(C4 y)
        {
            I1<I2> x = y;
        }
    }

    public class C6
        : I5
    {}

    public class C7
        : C4
    {}

    class Test3<T> where T : C4
    {
        void Test(T y3)
        {
            I1<I2> x = y3;
        }
    }

    class Test4<T> where T : I5
    {
        void Test(T y4)
        {
            I1<I2> x = y4;
        }
    }
    
    class Test5
    {
        void Test(I5 y5)
        {
            I1<I2> x = y5;
        }
    }

    public class C9
        : C8<I6<I2>>
    {}

    public class C11
        : C10<C4>
    {}

    public class C12
        : C10<I5>
    {}

//.........这里部分代码省略.........
开发者ID:nagyist,项目名称:roslyn,代码行数:101,代码来源:BadSymbolReference.cs

示例15: MissingBaseClass

        public void MissingBaseClass()
        {
            var lib1 = CreateCompilationWithMscorlib(@"
namespace ErrorTest
{
    public class C1
    {
        public void M1()
        {}
    }

    public class C6<T> where T : C1
    {}
}", compOptions: TestOptions.Dll, assemblyName: "MissingBaseClass1");

            var lib1Ref = new CSharpCompilationReference(lib1);

            var lib2 = CreateCompilationWithMscorlib(@"
namespace ErrorTest
{
    public class C2 : C1
    {}
}", new[] { lib1Ref }, TestOptions.Dll, assemblyName: "MissingBaseClass2");

            var lib2Ref = new CSharpCompilationReference(lib2);

            var lib3 = CreateCompilationWithMscorlib(@"
namespace ErrorTest
{
    public class C4 : C2
    {}
}", new[] { lib1Ref, lib2Ref }, TestOptions.Dll, assemblyName: "MissingBaseClass3");

            var lib3Ref = new CSharpCompilationReference(lib3);

            var lib4Def = @"
namespace ErrorTest
{
    class Test
    {
        void _Test(C4 y)
        {
            C1 x = y;
        }
    }

    public class C5 : C4
    {}

    class Test2
    {
        void _Test2(C4 y)
        {
            y.M1();
        }
    }

    class Test3<T> where T : C4
    {
        void Test(T y3)
        {
            C1 x = y3;
            y3.M1();
        }
    }

    public class C7 : C6<C4>
    {}

    class Test4
    {
        void Test(C6<C4> x)
        { }
    }
}";

            var lib4 = CreateCompilationWithMscorlib(lib4Def, new[] { lib1Ref, lib3Ref }, TestOptions.Dll);

            DiagnosticDescription[] expectedErrors =
            {
                // (12,23): error CS0012: The type 'ErrorTest.C2' is defined in an assembly that is not referenced. You must add a reference to assembly 'MissingBaseClass2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
                //     public class C5 : C4
                Diagnostic(ErrorCode.ERR_NoTypeDef, "C4").WithArguments("ErrorTest.C2", "MissingBaseClass2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"),
                // (32,18): error CS0311: The type 'ErrorTest.C4' cannot be used as type parameter 'T' in the generic type or method 'ErrorTest.C6<T>'. There is no implicit reference conversion from 'ErrorTest.C4' to 'ErrorTest.C1'.
                //     public class C7 : C6<C4>
                Diagnostic(ErrorCode.ERR_GenericConstraintNotSatisfiedRefType, "C7").WithArguments("ErrorTest.C6<T>", "ErrorTest.C1", "T", "ErrorTest.C4"),
                // (32,18): error CS0012: The type 'ErrorTest.C2' is defined in an assembly that is not referenced. You must add a reference to assembly 'MissingBaseClass2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
                //     public class C7 : C6<C4>
                Diagnostic(ErrorCode.ERR_NoTypeDef, "C7").WithArguments("ErrorTest.C2", "MissingBaseClass2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"),
                // (37,26): error CS0311: The type 'ErrorTest.C4' cannot be used as type parameter 'T' in the generic type or method 'ErrorTest.C6<T>'. There is no implicit reference conversion from 'ErrorTest.C4' to 'ErrorTest.C1'.
                //         void Test(C6<C4> x)
                Diagnostic(ErrorCode.ERR_GenericConstraintNotSatisfiedRefType, "x").WithArguments("ErrorTest.C6<T>", "ErrorTest.C1", "T", "ErrorTest.C4"),
                // (37,26): error CS0012: The type 'ErrorTest.C2' is defined in an assembly that is not referenced. You must add a reference to assembly 'MissingBaseClass2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
                //         void Test(C6<C4> x)
                Diagnostic(ErrorCode.ERR_NoTypeDef, "x").WithArguments("ErrorTest.C2", "MissingBaseClass2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"),
                // (19,15): error CS0012: The type 'ErrorTest.C2' is defined in an assembly that is not referenced. You must add a reference to assembly 'MissingBaseClass2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
                //             y.M1();
                Diagnostic(ErrorCode.ERR_NoTypeDef, "M1").WithArguments("ErrorTest.C2", "MissingBaseClass2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"),
                // (19,15): error CS1061: 'ErrorTest.C4' does not contain a definition for 'M1' and no extension method 'M1' accepting a first argument of type 'ErrorTest.C4' could be found (are you missing a using directive or an assembly reference?)
                //             y.M1();
//.........这里部分代码省略.........
开发者ID:nagyist,项目名称:roslyn,代码行数:101,代码来源:BadSymbolReference.cs


注:本文中的CSharpCompilationReference类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。