• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# AssemblyIdentity类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: AssemblyReference

 /// <summary>
 /// Allocates a reference to a .NET assembly.
 /// </summary>
 /// <param name="host">Provides a standard abstraction over the applications that host components that provide or consume objects from the metadata model.</param>
 /// <param name="assemblyIdentity">The identity of the referenced assembly.</param>
 /// <param name="isRetargetable">True if the implementation of the referenced assembly used at runtime is not expected to match the version seen at compile time.</param>
 /// <param name="containsForeignTypes">
 /// True if the referenced assembly contains types that describe objects that are neither COM objects nor objects that are managed by the CLR.
 /// Instances of such types are created and managed by another runtime and are accessed by CLR objects via some form of interoperation mechanism.
 /// </param>
 public AssemblyReference(IMetadataHost host, AssemblyIdentity assemblyIdentity, bool isRetargetable = false, bool containsForeignTypes = false)
 {
     this.host = host;
       this.assemblyIdentity = assemblyIdentity;
       this.isRetargetable = isRetargetable;
       this.containsForeignTypes = containsForeignTypes;
 }
开发者ID:rasiths,项目名称:visual-profiler,代码行数:17,代码来源:PlatformTypes.cs


示例2: FusionAssemblyNameRoundTrip

        public void FusionAssemblyNameRoundTrip()
        {
            RoundTrip(new AssemblyName("foo"));
            RoundTrip(new AssemblyName { Name = "[email protected]#$%^&*()_+={}:\"<>?[];',./" });
            RoundTrip(new AssemblyName("\\,"));
            RoundTrip(new AssemblyName("\\\""));

            RoundTrip(new AssemblyIdentity("foo").ToAssemblyName());

            // 0xffff version is not included in AssemblyName.FullName for some reason:
            var name = new AssemblyIdentity("foo", version: new Version(0xffff, 0xffff, 0xffff, 0xffff)).ToAssemblyName();
            RoundTrip(name, testFullName: false);
            var obj = FusionAssemblyIdentity.ToAssemblyNameObject(name);
            var display = FusionAssemblyIdentity.GetDisplayName(obj, FusionAssemblyIdentity.ASM_DISPLAYF.FULL);
            Assert.Equal("foo, Version=65535.65535.65535.65535, Culture=neutral, PublicKeyToken=null", display);

            RoundTrip(new AssemblyIdentity("foo", version: new Version(1, 2, 3, 4)).ToAssemblyName());
            RoundTrip(new AssemblyName("foo") { Version = new Version(1, 2, 3, 4) });

            RoundTrip(new AssemblyIdentity("foo", cultureName: CultureInfo.CurrentCulture.Name).ToAssemblyName());
            RoundTrip(new AssemblyIdentity("foo", cultureName: "").ToAssemblyName());
            RoundTrip(new AssemblyName("foo") { CultureInfo = CultureInfo.InvariantCulture });

            RoundTrip(new AssemblyIdentity("foo", version: new Version(1, 2, 3, 4), cultureName: "en-US").ToAssemblyName());
            RoundTrip(new AssemblyIdentity("foo", publicKeyOrToken: new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }.AsImmutableOrNull()).ToAssemblyName());
            RoundTrip(new AssemblyIdentity("foo", version: new Version(1, 2, 3, 4), cultureName: CultureInfo.CurrentCulture.Name, publicKeyOrToken: new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }.AsImmutableOrNull()).ToAssemblyName());

            RoundTrip(new AssemblyIdentity("foo", isRetargetable: true).ToAssemblyName());
            RoundTrip(new AssemblyIdentity("foo", contentType: AssemblyContentType.WindowsRuntime).ToAssemblyName());
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:30,代码来源:FusionAssemblyIdentityTests.cs


示例3: GetErrorMessageAndMissingAssemblyIdentities

        internal string GetErrorMessageAndMissingAssemblyIdentities(DiagnosticBag diagnostics, DiagnosticFormatter formatter, CultureInfo preferredUICulture, AssemblyIdentity linqLibrary, out bool useReferencedModulesOnly, out ImmutableArray<AssemblyIdentity> missingAssemblyIdentities)
        {
            var errors = diagnostics.AsEnumerable().Where(d => d.Severity == DiagnosticSeverity.Error);
            foreach (var error in errors)
            {
                missingAssemblyIdentities = this.GetMissingAssemblyIdentities(error, linqLibrary);
                if (!missingAssemblyIdentities.IsDefault)
                {
                    break;
                }
            }

            if (missingAssemblyIdentities.IsDefault)
            {
                missingAssemblyIdentities = ImmutableArray<AssemblyIdentity>.Empty;
            }

            useReferencedModulesOnly = errors.All(HasDuplicateTypesOrAssemblies);

            var firstError = errors.FirstOrDefault();
            Debug.Assert(firstError != null);

            var simpleMessage = firstError as SimpleMessageDiagnostic;
            return (simpleMessage != null) ?
                simpleMessage.GetMessage() :
                formatter.Format(firstError, preferredUICulture ?? CultureInfo.CurrentUICulture);
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:27,代码来源:EvaluationContextBase.cs


示例4: AssemblyIdentityAndLocation

            public AssemblyIdentityAndLocation(AssemblyIdentity identity, string location)
            {
                Debug.Assert(identity != null && location != null);

                this.Identity = identity;
                this.Location = location;
            }
开发者ID:robertoenbarcelona,项目名称:roslyn,代码行数:7,代码来源:InteractiveAssemblyLoader.cs


示例5: AddMissingReferenceCodeAction

 public AddMissingReferenceCodeAction(Project project, string title, ProjectReference projectReferenceToAdd, AssemblyIdentity missingAssemblyIdentity)
 {
     _project = project;
     Title = title;
     _projectReferenceToAdd = projectReferenceToAdd;
     _missingAssemblyIdentity = missingAssemblyIdentity;
 }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:7,代码来源:AddMissingReferenceCodeAction.cs


示例6: MultipleAssemblyArguments

 public void MultipleAssemblyArguments()
 {
     var identity1 = new AssemblyIdentity(GetUniqueName());
     var identity2 = new AssemblyIdentity(GetUniqueName());
     Assert.Equal(identity1, GetMissingAssemblyIdentity(ErrorCode.ERR_NoTypeDef, identity1, identity2));
     Assert.Equal(identity2, GetMissingAssemblyIdentity(ErrorCode.ERR_NoTypeDef, identity2, identity1));
 }
开发者ID:cristinamanum,项目名称:roslyn,代码行数:7,代码来源:MissingAssemblyTests.cs


示例7: LoadedAssemblyInfo

            public LoadedAssemblyInfo(Assembly assembly, AssemblyIdentity identity, string locationOpt)
            {
                Debug.Assert(assembly != null && identity != null);

                Assembly = assembly;
                Identity = identity;
                LocationOpt = locationOpt;
            }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:8,代码来源:InteractiveAssemblyLoader.cs


示例8: ExternAliasRecord

        public ExternAliasRecord(string alias, AssemblyIdentity targetIdentity)
        {
            Debug.Assert(alias != null);
            Debug.Assert(targetIdentity != null);

            Alias = alias;
            TargetAssembly = targetIdentity;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:8,代码来源:ExternAliasRecord.cs


示例9: UnifiedAssembly

        public UnifiedAssembly(AssemblySymbol targetAssembly, AssemblyIdentity originalReference)
        {
            Debug.Assert(originalReference != null);
            Debug.Assert(targetAssembly != null);

            this.OriginalReference = originalReference;
            this.TargetAssembly = targetAssembly;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:8,代码来源:UnifiedAssembly.cs


示例10: Equality_InvariantCulture

        public void Equality_InvariantCulture()
        {
            var neutral1 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "NEUtral", RoPublicKeyToken1, hasPublicKey: false, isRetargetable: false);
            var neutral2 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), null, RoPublicKeyToken1, hasPublicKey: false, isRetargetable: false);
            var neutral3 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "neutral", RoPublicKeyToken1, hasPublicKey: false, isRetargetable: false);
            var invariant = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", RoPublicKeyToken1, hasPublicKey: false, isRetargetable: false);

            Assert.True(neutral1.Equals(invariant));
            Assert.True(neutral2.Equals(invariant));
            Assert.True(neutral3.Equals(invariant));
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:11,代码来源:AssemblyIdentityTests.cs


示例11: MetadataAsSourceGeneratedFileInfo

        public MetadataAsSourceGeneratedFileInfo(string rootPath, Project sourceProject, INamedTypeSymbol topLevelNamedType)
        {
            this.SourceProjectId = sourceProject.Id;
            this.Workspace = sourceProject.Solution.Workspace;
            this.LanguageName = sourceProject.Language;
            this.References = sourceProject.MetadataReferences.ToImmutableArray();
            this.AssemblyIdentity = topLevelNamedType.ContainingAssembly.Identity;

            var extension = sourceProject.Language == LanguageNames.CSharp ? ".cs" : ".vb";

            var directoryName = Guid.NewGuid().ToString("N");
            this.TemporaryFilePath = Path.Combine(rootPath, directoryName, topLevelNamedType.Name + extension);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:13,代码来源:MetadataAsSourceGeneratedFileInfo.cs


示例12: MetadataDefinitionItem

 public MetadataDefinitionItem(
     ImmutableArray<string> tags,
     ImmutableArray<TaggedText> displayParts,
     bool displayIfNoReferences,
     Solution solution, ISymbol definition)
     : base(tags, displayParts,
           GetOriginationParts(definition),
           ImmutableArray<DocumentLocation>.Empty,
           displayIfNoReferences)
 {
     _workspace = solution.Workspace;
     _symbolKey = definition.GetSymbolKey();
     _symbolAssemblyIdentity = definition.ContainingAssembly?.Identity;
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:14,代码来源:DefinitionItem.SymbolDefinitionItem.cs


示例13: Equality

        public void Equality()
        {
            var id1 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", RoPublicKey1, hasPublicKey: true, isRetargetable: false);
            var id11 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", RoPublicKey1, hasPublicKey: true, isRetargetable: false);
            var id2 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", RoPublicKeyToken1, hasPublicKey: false, isRetargetable: false);
            var id22 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", RoPublicKeyToken1, hasPublicKey: false, isRetargetable: false);

            var id3 = new AssemblyIdentity("Foo!", new Version(1, 0, 0, 0), "", RoPublicKeyToken1, hasPublicKey: false, isRetargetable: false);
            var id4 = new AssemblyIdentity("Foo", new Version(1, 0, 1, 0), "", RoPublicKeyToken1, hasPublicKey: false, isRetargetable: false);
            var id5 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "en-US", RoPublicKeyToken1, hasPublicKey: false, isRetargetable: false);
            var id6 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", default(ImmutableArray<byte>), hasPublicKey: false, isRetargetable: false);
            var id7 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", RoPublicKeyToken1, hasPublicKey: true, isRetargetable: false);
            var id8 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", RoPublicKey1, hasPublicKey: true, isRetargetable: true);

            var win1 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", RoPublicKey1, hasPublicKey: true, isRetargetable: false, contentType: AssemblyContentType.WindowsRuntime);
            var win2 = new AssemblyIdentity("Bar", new Version(1, 0, 0, 0), "", RoPublicKey1, hasPublicKey: true, isRetargetable: false, contentType: AssemblyContentType.WindowsRuntime);
            var win3 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", RoPublicKey1, hasPublicKey: true, isRetargetable: false, contentType: AssemblyContentType.WindowsRuntime);

            Assert.True(id1.Equals(id1));
            Assert.True(id1.Equals(id2));
            Assert.True(id2.Equals(id1));
            Assert.True(id1.Equals(id11));
            Assert.True(id11.Equals(id1));
            Assert.True(id2.Equals(id22));
            Assert.True(id22.Equals(id2));

            Assert.False(id1.Equals(id3));
            Assert.False(id1.Equals(id4));
            Assert.False(id1.Equals(id5));
            Assert.False(id1.Equals(id6));
            Assert.False(id1.Equals(id7));
            Assert.False(id1.Equals(id8));

            Assert.Equal((object)id1, id1);
            Assert.NotNull(id1);
            Assert.False(id2.Equals((AssemblyIdentity)null));

            Assert.Equal(id1.GetHashCode(), id2.GetHashCode());

            Assert.False(win1.Equals(win2));
            Assert.False(win1.Equals(id1));
            Assert.True(win1.Equals(win3));

            Assert.Equal(win1.GetHashCode(), win3.GetHashCode());
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:45,代码来源:AssemblyIdentityTests.cs


示例14: CreateAsync

        public static async Task<CodeAction> CreateAsync(Project project, AssemblyIdentity missingAssemblyIdentity, CancellationToken cancellationToken)
        {
            var dependencyGraph = project.Solution.GetProjectDependencyGraph();

            // We want to find a project that generates this assembly, if one so exists. We therefore 
            // search all projects that our project with an error depends on. We want to do this for
            // complicated and evil scenarios like this one:
            //
            //     C -> B -> A
            //
            //     A'
            //
            // Where, for some insane reason, A and A' are two projects that both emit an assembly 
            // by the same name. So imagine we are using a type in B from C, and we are missing a 
            // reference to A.dll. Both A and A' are candidates, but we know we can throw out A'
            // since whatever type from B we are using that's causing the error, we know that type 
            // isn't referencing A'. Put another way: this code action adds a reference, but should 
            // never change the transitive closure of project references that C has.
            //
            // Doing this filtering also means we get to check less projects (good), and ensures that
            // whatever project reference we end up adding won't add a circularity (also good.)
            foreach (var candidateProjectId in dependencyGraph.GetProjectsThatThisProjectTransitivelyDependsOn(project.Id))
            {
                var candidateProject = project.Solution.GetProject(candidateProjectId);
                if (string.Equals(missingAssemblyIdentity.Name, candidateProject.AssemblyName, StringComparison.OrdinalIgnoreCase))
                {
                    // The name matches, so let's see if the full identities are equal. 
                    var compilation = await candidateProject.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
                    if (missingAssemblyIdentity.Equals(compilation.Assembly.Identity))
                    {
                        // It matches, so just add a reference to this
                        return new AddMissingReferenceCodeAction(project,
                            string.Format(FeaturesResources.Add_project_reference_to_0, candidateProject.Name),
                            new ProjectReference(candidateProjectId), missingAssemblyIdentity);
                    }
                }
            }

            // No matching project, so metadata reference
            var description = string.Format(FeaturesResources.Add_reference_to_0, missingAssemblyIdentity.GetDisplayName());
            return new AddMissingReferenceCodeAction(project, description, null, missingAssemblyIdentity);
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:42,代码来源:AddMissingReferenceCodeAction.cs


示例15: ERR_NoTypeDef

        public void ERR_NoTypeDef()
        {
            var libSource = @"
public class Missing { }
";

            var source = @"
public class C
{
    public void M(Missing parameter)
    {
    }
}
";
            var libRef = CreateCompilationWithMscorlib(libSource, assemblyName: "Lib").EmitToImageReference();
            var comp = CreateCompilationWithMscorlib(source, new[] { libRef }, TestOptions.DebugDll);
            var context = CreateMethodContextWithReferences(comp, "C.M", MscorlibRef);

            var expectedError = "error CS0012: The type 'Missing' is defined in an assembly that is not referenced. You must add a reference to assembly 'Lib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.";
            var expectedMissingAssemblyIdentity = new AssemblyIdentity("Lib");

            ResultProperties resultProperties;
            string actualError;
            ImmutableArray<AssemblyIdentity> actualMissingAssemblyIdentities;

            context.CompileExpression(
                DefaultInspectionContext.Instance,
                "parameter",
                DkmEvaluationFlags.TreatAsExpression,
                DiagnosticFormatter.Instance,
                out resultProperties,
                out actualError,
                out actualMissingAssemblyIdentities,
                EnsureEnglishUICulture.PreferredOrNull,
                testData: null);
            Assert.Equal(expectedError, actualError);
            Assert.Equal(expectedMissingAssemblyIdentity, actualMissingAssemblyIdentities.Single());
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:38,代码来源:MissingAssemblyTests.cs


示例16: MissingType

        public void MissingType()
        {
            var libSource = @"
public class Missing { }
";

            var source = @"
public class C
{
    Missing field;    

    public void M(Missing parameter)
    {
        Missing local;
    }
}
";
            var libRef = CreateCompilationWithMscorlib(libSource, assemblyName: "Lib").EmitToImageReference();
            var comp = CreateCompilationWithMscorlib(source, new[] { libRef }, TestOptions.DebugDll);

            byte[] exeBytes;
            byte[] pdbBytes;
            ImmutableArray<MetadataReference> unusedReferences;
            var result = comp.EmitAndGetReferences(out exeBytes, out pdbBytes, out unusedReferences);
            Assert.True(result);

            var runtime = CreateRuntimeInstance(GetUniqueName(), ImmutableArray.Create(MscorlibRef), exeBytes, new SymReader(pdbBytes));
            var context = CreateMethodContext(runtime, "C.M");

            var expectedError = "error CS0012: The type 'Missing' is defined in an assembly that is not referenced. You must add a reference to assembly 'Lib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.";
            var expectedMissingAssemblyIdentity = new AssemblyIdentity("Lib");

            ResultProperties resultProperties;
            string actualError;
            ImmutableArray<AssemblyIdentity> actualMissingAssemblyIdentities;

            Action<string> verify = expr =>
            {
                context.CompileExpression(
                    expr,
                    DkmEvaluationFlags.TreatAsExpression,
                    NoAliases,
                    DiagnosticFormatter.Instance,
                    out resultProperties,
                    out actualError,
                    out actualMissingAssemblyIdentities,
                    EnsureEnglishUICulture.PreferredOrNull,
                    testData: null);
                Assert.Equal(expectedError, actualError);
                Assert.Equal(expectedMissingAssemblyIdentity, actualMissingAssemblyIdentities.Single());
            };

            verify("M(null)");
            verify("field");
            verify("field.Method");
            verify("parameter");
            verify("parameter.Method");
            verify("local");
            verify("local.Method");

            // Note that even expressions that don't require the missing type will fail because
            // the method we synthesize refers to the original locals and parameters.
            verify("0");
        }
开发者ID:daking2014,项目名称:roslyn,代码行数:64,代码来源:ExpressionCompilerTests.cs


示例17: GetMissingAssemblyIdentities

 internal override ImmutableArray<AssemblyIdentity> GetMissingAssemblyIdentities(Diagnostic diagnostic, AssemblyIdentity linqLibrary)
 {
     return GetMissingAssemblyIdentitiesHelper((ErrorCode)diagnostic.Code, diagnostic.Arguments, linqLibrary);
 }
开发者ID:daking2014,项目名称:roslyn,代码行数:4,代码来源:EvaluationContext.cs


示例18: GetAssemblyName

            private AssemblyName GetAssemblyName(string fullPath)
            {
                using (var stream = PortableShim.File.OpenRead(fullPath))
                {
                    using (var peReader = new PEReader(stream))
                    {
                        var reader = peReader.GetMetadataReader();
                        var assemblyDef = reader.GetAssemblyDefinition();

                        var name = reader.GetString(assemblyDef.Name);

                        var cultureName = assemblyDef.Culture.IsNil
                            ? null
                            : reader.GetString(assemblyDef.Culture);

                        var publicKeyOrToken = reader.GetBlobContent(assemblyDef.PublicKey);
                        var hasPublicKey = !publicKeyOrToken.IsEmpty;

                        if (publicKeyOrToken.IsEmpty)
                        {
                            publicKeyOrToken = default(ImmutableArray<byte>);
                        }

                        var identity = new AssemblyIdentity(
                            name: name,
                            version: assemblyDef.Version,
                            cultureName: cultureName,
                            publicKeyOrToken: publicKeyOrToken,
                            hasPublicKey: hasPublicKey,
                            isRetargetable: (assemblyDef.Flags & AssemblyFlags.Retargetable) != 0,
                            contentType: (AssemblyContentType)((int)(assemblyDef.Flags & AssemblyFlags.ContentTypeMask) >> 9));

                        return new AssemblyName(identity.GetDisplayName());
                    }
                }
            }
开发者ID:hbarve1,项目名称:roslyn,代码行数:36,代码来源:HostAnalyzerManager.cs


示例19: MultiTargeting2

        public void MultiTargeting2()
        {
            var varMTTestLib1_V1_Name = new AssemblyIdentity("MTTestLib1", new Version("1.0.0.0"));

            var varC_MTTestLib1_V1 = CreateCompilation(varMTTestLib1_V1_Name,
                           new string[] {
                               // AssemblyPaths.SymbolsTests.V1.MTTestModule1.netmodule
                               @"
public class Class1
{
}
"
                               },
                           new[] { TestReferences.NetFx.v4_0_30319.mscorlib });

            var asm_MTTestLib1_V1 = varC_MTTestLib1_V1.SourceAssembly().BoundReferences();

            var varMTTestLib2_Name = new AssemblyIdentity("MTTestLib2");

            var varC_MTTestLib2 = CreateCompilation(varMTTestLib2_Name,
                           new string[] {
                               // AssemblyPaths.SymbolsTests.V1.MTTestModule2.netmodule
                               @"
public class Class4
{
    Class1 Foo()
    {
        return null;
    }

    public Class1 Bar;

}
"
                               },
                           new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, varC_MTTestLib1_V1.ToMetadataReference() });

            var asm_MTTestLib2 = varC_MTTestLib2.SourceAssembly().BoundReferences();

            Assert.Same(asm_MTTestLib2[0], asm_MTTestLib1_V1[0]);
            Assert.Same(asm_MTTestLib2[1], varC_MTTestLib1_V1.SourceAssembly());

            var c2 = CreateCompilation(new AssemblyIdentity("c2"),
                           null,
                           new MetadataReference[]
                               {
                                   TestReferences.NetFx.v4_0_30319.mscorlib,
                                   varC_MTTestLib2.ToMetadataReference(),
                                   varC_MTTestLib1_V1.ToMetadataReference()
                               });

            var asm2 = c2.SourceAssembly().BoundReferences();

            Assert.Same(asm2[0], asm_MTTestLib1_V1[0]);
            Assert.Same(asm2[1], varC_MTTestLib2.SourceAssembly());
            Assert.Same(asm2[2], varC_MTTestLib1_V1.SourceAssembly());

            Assert.Equal("MTTestLib2", asm2[1].Identity.Name);
            Assert.Equal(2, (from a in asm2[1].BoundReferences() where !a.IsMissing select a).Count());
            Assert.Equal(1, (from a in asm2[1].BoundReferences() where object.ReferenceEquals(a, asm2[0]) select a).Count());
            Assert.Equal(1, (from a in asm2[1].BoundReferences() where object.ReferenceEquals(a, asm2[2]) select a).Count());

            var retval1 = asm2[1].GlobalNamespace.GetTypeMembers("Class4").
                          Single().
                          GetMembers("Foo").OfType<MethodSymbol>().Single().ReturnType;

            Assert.NotEqual(SymbolKind.ErrorType, retval1.Kind);
            Assert.Same(retval1, asm2[2].GlobalNamespace.GetMembers("Class1").Single());

            Assert.Equal("MTTestLib1", asm2[2].Identity.Name);
            Assert.Equal(1, asm2[2].Identity.Version.Major);
            Assert.Equal(1, (from a in asm2[2].BoundReferences() where !a.IsMissing select a).Count());
            Assert.Equal(1, (from a in asm2[2].BoundReferences() where object.ReferenceEquals(a, asm2[0]) select a).Count());

            var varMTTestLib1_V2_Name = new AssemblyIdentity("MTTestLib1", new Version("2.0.0.0"));

            var varC_MTTestLib1_V2 = CreateCompilation(varMTTestLib1_V2_Name,
                           new string[] {
                               // AssemblyPaths.SymbolsTests.V2.MTTestModule1.netmodule
                               @"
public class Class1
{
}

public class Class2
{
}
"
                               },
                           new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib });

            var asm_MTTestLib1_V2 = varC_MTTestLib1_V2.SourceAssembly().BoundReferences();

            var varMTTestLib3_Name = new AssemblyIdentity("MTTestLib3");

            var varC_MTTestLib3 = CreateCompilation(varMTTestLib3_Name,
                new string[] {
                    // AssemblyPaths.SymbolsTests.V2.MTTestModule3.netmodule
                    @"
public class Class5
//.........这里部分代码省略.........
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:101,代码来源:CompilationCreationTests.cs


示例20: MultiTargeting5

        public void MultiTargeting5()
        {
            var c1_Name = new AssemblyIdentity("c1");

            var text = @"
class Module1
{
    Class4 M1()
    {}

    Class4.Class4_1 M2()
    {}

    Class4 M3()
    {}
}
";
            var tree = Parse(text);

            var c1 = CreateCompilationWithMscorlib(tree, new MetadataReference[]
            {
                TestReferences.SymbolsTests.V1.MTTestLib1.dll,
                TestReferences.SymbolsTests.V1.MTTestModule2.netmodule
            });

            var c2_Name = new AssemblyIdentity("MTTestLib2");

            var c2 = CreateCompilation(c2_Name, null, new MetadataReference[]
            {
                TestReferences.NetFx.v4_0_30319.mscorlib,
                TestReferences.SymbolsTests.V2.MTTestLib1.dll,
                new CSharpCompilationReference(c1)
            });

            SourceAssemblySymbol c1AsmSource = (SourceAssemblySymbol)c1.Assembly;
            PEAssemblySymbol Lib1_V1 = (PEAssemblySymbol)c1AsmSource.Modules[0].GetReferencedAssemblySymbols()[1];
            PEModuleSymbol module1 = (PEModuleSymbol)c1AsmSource.Modules[1];

            Assert.Equal(LocationKind.MetadataFile, ((MetadataLocation)Lib1_V1.Locations[0]).Kind);
            SourceAssemblySymbol c2AsmSource = (SourceAssemblySymbol)c2.Assembly;
            RetargetingAssemblySymbol c1AsmRef = (RetargetingAssemblySymbol)c2AsmSource.Modules[0].GetReferencedAssemblySymbols()[2];
            PEAssemblySymbol Lib1_V2 = (PEAssemblySymbol)c2AsmSource.Modules[0].GetReferencedAssemblySymbols()[1];
            PEModuleSymbol module2 = (PEModuleSymbol)c1AsmRef.Modules[1];

            Assert.Equal(1, Lib1_V1.Identity.Version.Major);
            Assert.Equal(2, Lib1_V2.Identity.Version.Major);

            Assert.NotEqual(module1, module2);
            Assert.Same(module1.Module, module2.Module);

            NamedTypeSymbol classModule1 = c1AsmRef.Modules[0].GlobalNamespace.GetTypeMembers("Module1").Single();
            MethodSymbol m1 = classModule1.GetMembers("M1").OfType<MethodSymbol>().Single();
            MethodSymbol m2 = classModule1.GetMembers("M2").OfType<MethodSymbol>().Single();
            MethodSymbol m3 = classModule1.GetMembers("M3").OfType<MethodSymbol>().Single();

            Assert.Same(module2, m1.ReturnType.ContainingModule);
            Assert.Same(module2, m2.ReturnType.ContainingModule);
            Assert.Same(module2, m3.ReturnType.ContainingModule);
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:59,代码来源:CompilationCreationTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# AssemblyInfo类代码示例发布时间:2022-05-24
下一篇:
C# AssemblyHashAlgorithm类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap