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

C# MetadataReference类代码示例

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

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



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

示例1: CompileAndVerifyIL

        private CompilationVerifier CompileAndVerifyIL(string source, string methodName, string expectedOptimizedIL = null, string expectedUnoptimizedIL = null, 
            MetadataReference[] references = null)
        {
            references = references ?? new[] { SystemCoreRef, CSharpRef };

            // verify that we emit correct optimized and unoptimized IL:
            var unoptimizedCompilation = CreateCompilationWithMscorlib45(source, references, compOptions: TestOptions.UnsafeDll.WithMetadataImportOptions(MetadataImportOptions.All).WithOptimizations(false));
            var optimizedCompilation = CreateCompilationWithMscorlib45(source, references, compOptions: TestOptions.UnsafeDll.WithMetadataImportOptions(MetadataImportOptions.All).WithOptimizations(true));

            var unoptimizedVerifier = CompileAndVerify(unoptimizedCompilation);
            var optimizedVerifier = CompileAndVerify(optimizedCompilation);

            // check what IL we emit exactly:
            if (expectedUnoptimizedIL != null)
            {
                unoptimizedVerifier.VerifyIL(methodName, expectedUnoptimizedIL, realIL: true);
            }

            if (expectedOptimizedIL != null)
            {
                optimizedVerifier.VerifyIL(methodName, expectedOptimizedIL, realIL: true);
            }

            // return null if ambiguous
            return (expectedUnoptimizedIL != null) ^ (expectedOptimizedIL != null) ? (unoptimizedVerifier ?? optimizedVerifier) : null;
        }
开发者ID:nagyist,项目名称:roslyn,代码行数:26,代码来源:CodeGenDynamicTests.cs


示例2: GetSymbolsForReferences

        internal static AssemblySymbol[] GetSymbolsForReferences(
            CSharpCompilation[] compilations = null,
            byte[][] bytes = null,
            MetadataReference[] mrefs = null,
            CSharpCompilationOptions options = null)
        {
            var refs = new List<MetadataReference>();

            if (compilations != null)
            {
                foreach (var c in compilations)
                {
                    refs.Add(new CSharpCompilationReference(c));
                }
            }

            if (bytes != null)
            {
                foreach (var b in bytes)
                {
                    refs.Add(new MetadataImageReference(b.AsImmutableOrNull()));
                }
            }

            if (mrefs != null)
            {
                refs.AddRange(mrefs);
            }

            var tc1 = CSharpCompilation.Create(assemblyName: "Dummy", options: options ?? TestOptions.ReleaseDll, syntaxTrees: new SyntaxTree[0], references: refs);

           return (from @ref in refs select tc1.GetReferencedAssemblySymbol(@ref)).ToArray();
        }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:33,代码来源:MetadataTestHelpers.cs


示例3: TestOverloadResolutionWithDiff

        internal void TestOverloadResolutionWithDiff(string source, MetadataReference[] additionalRefs = null)
        {
            // The mechanism of this test is: we build the bound tree for the code passed in and then extract
            // from it the nodes that describe the method symbols. We then compare the description of
            // the symbols given to the comment that follows the call.

            var mscorlibRef = new MetadataImageReference(ProprietaryTestResources.NetFX.v4_0_30316_17626.mscorlib.AsImmutableOrNull(), display: "mscorlib");
            var references = new[] { mscorlibRef }.Concat(additionalRefs ?? SpecializedCollections.EmptyArray<MetadataReference>());

            var compilation = CreateCompilation(source, references, TestOptions.ReleaseDll);

            var method = (SourceMethodSymbol)compilation.GlobalNamespace.GetTypeMembers("C").Single().GetMembers("M").Single();
            var diagnostics = new DiagnosticBag();
            var block = MethodCompiler.BindMethodBody(method, new TypeCompilationState(method.ContainingType, compilation, null), diagnostics);
            var tree = BoundTreeDumperNodeProducer.MakeTree(block);
            var results = string.Join("\n", tree.PreorderTraversal().Select(edge => edge.Value)
                .Where(x => x.Text == "method" && x.Value != null)
                .Select(x => x.Value)
                .ToArray());

            // var r = string.Join("\n", tree.PreorderTraversal().Select(edge => edge.Value).ToArray();

            var expected = string.Join("\n", source
                .Split(new[] { "\r\n" }, System.StringSplitOptions.RemoveEmptyEntries)
                .Where(x => x.Contains("//-"))
                .Select(x => x.Substring(x.IndexOf("//-") + 3))
                .ToArray());

            AssertEx.Equal(expected, results);
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:30,代码来源:OverloadResolutionTestBase.cs


示例4: CompileAndVerifyIL

        private CompilationVerifier CompileAndVerifyIL(
            string source,
            string methodName,
            string expectedOptimizedIL = null,
            string expectedUnoptimizedIL = null,
            MetadataReference[] references = null,
            bool allowUnsafe = false,
            [CallerFilePath]string callerPath = null,
            [CallerLineNumber]int callerLine = 0)
        {
            references = references ?? new[] { SystemCoreRef, CSharpRef };

            // verify that we emit correct optimized and unoptimized IL:
            var unoptimizedCompilation = CreateCompilationWithMscorlib45(source, references, options: TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All).WithAllowUnsafe(allowUnsafe));
            var optimizedCompilation = CreateCompilationWithMscorlib45(source, references, options: TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.All).WithAllowUnsafe(allowUnsafe));

            var unoptimizedVerifier = CompileAndVerify(unoptimizedCompilation);
            var optimizedVerifier = CompileAndVerify(optimizedCompilation);

            // check what IL we emit exactly:
            if (expectedUnoptimizedIL != null)
            {
                unoptimizedVerifier.VerifyIL(methodName, expectedUnoptimizedIL, realIL: true, sequencePoints: methodName, callerPath: callerPath, callerLine: callerLine);
            }

            if (expectedOptimizedIL != null)
            {
                optimizedVerifier.VerifyIL(methodName, expectedOptimizedIL, realIL: true, callerPath: callerPath, callerLine: callerLine);
            }

            // return null if ambiguous
            return (expectedUnoptimizedIL != null) ^ (expectedOptimizedIL != null) ? (unoptimizedVerifier ?? optimizedVerifier) : null;
        }
开发者ID:nemec,项目名称:roslyn,代码行数:33,代码来源:CodeGenDynamicTests.cs


示例5: CreateCompilation

 internal static Compilation CreateCompilation(string source, MetadataReference[] references, string assemblyName, CSharpCompilationOptions options = null)
 {
     return CSharpCompilation.Create(
         assemblyName,
         new[] { SyntaxFactory.ParseSyntaxTree(source) },
         references,
         options ?? new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
 }
开发者ID:JackWangCUMT,项目名称:roslyn,代码行数:8,代码来源:TestCompilationFactory.cs


示例6: CreateChecksum

        public Checksum CreateChecksum(MetadataReference reference, CancellationToken cancellationToken)
        {
            var portable = reference as PortableExecutableReference;
            if (portable != null)
            {
                return CreatePortableExecutableReferenceChecksum(portable, cancellationToken);
            }

            throw ExceptionUtilities.UnexpectedValue(reference.GetType());
        }
开发者ID:natidea,项目名称:roslyn,代码行数:10,代码来源:AbstractReferenceSerializationService.cs


示例7: GetMetadataReferenceFilePath

        private static string GetMetadataReferenceFilePath(MetadataReference metadataReference)
        {
            var executabeReference = metadataReference as PortableExecutableReference;
            if (executabeReference == null)
            {
                return null;
            }

            return executabeReference.FilePath;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:10,代码来源:SymbolFinder_Declarations.cs


示例8: AddProjectWithMetadataReferences

 public static Solution AddProjectWithMetadataReferences(Solution solution, string projectName, string languageName, string code, MetadataReference metadataReference, params ProjectId[] projectReferences)
 {
     var suffix = languageName == LanguageNames.CSharp ? "cs" : "vb";
     var pid = ProjectId.CreateNewId();
     var did = DocumentId.CreateNewId(pid);
     var pi = ProjectInfo.Create(
         pid,
         VersionStamp.Default,
         projectName,
         projectName,
         languageName,
         metadataReferences: new[] { metadataReference },
         projectReferences: projectReferences.Select(p => new ProjectReference(p)));
     return solution.AddProject(pi).AddDocument(did, $"{projectName}.{suffix}", SourceText.From(code));
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:15,代码来源:ServicesTestBase.cs


示例9: ModuleInstance

        internal ModuleInstance(
            MetadataReference metadataReference,
            ModuleMetadata moduleMetadata,
            Guid moduleVersionId,
            byte[] fullImage,
            byte[] metadataOnly,
            object symReader,
            bool includeLocalSignatures)
        {
            Debug.Assert((fullImage == null) || (fullImage.Length > metadataOnly.Length));

            this.MetadataReference = metadataReference;
            this.ModuleMetadata = moduleMetadata;
            this.ModuleVersionId = moduleVersionId;
            this.FullImage = fullImage;
            this.MetadataOnly = metadataOnly;
            this.MetadataHandle = GCHandle.Alloc(metadataOnly, GCHandleType.Pinned);
            this.SymReader = symReader; // should be non-null if and only if there are symbols
            _includeLocalSignatures = includeLocalSignatures;
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:20,代码来源:ModuleInstance.cs


示例10: WriteTo

        public void WriteTo(MetadataReference reference, ObjectWriter writer, CancellationToken cancellationToken)
        {
            var portable = reference as PortableExecutableReference;
            if (portable != null)
            {
                var supportTemporaryStorage = portable as ISupportTemporaryStorage;
                if (supportTemporaryStorage != null)
                {
                    if (TryWritePortableExecutableReferenceBackedByTemporaryStorageTo(supportTemporaryStorage, writer, cancellationToken))
                    {
                        return;
                    }
                }

                WritePortableExecutableReferenceTo(portable, writer, cancellationToken);
                return;
            }

            throw ExceptionUtilities.UnexpectedValue(reference.GetType());
        }
开发者ID:natidea,项目名称:roslyn,代码行数:20,代码来源:AbstractReferenceSerializationService.cs


示例11: AppConfig1

        public void AppConfig1()
        {
            var references = new MetadataReference[]
            {
                TestReferences.NetFx.v4_0_30319.mscorlib,
                TestReferences.NetFx.v4_0_30319.System,
                TestReferences.NetFx.silverlight_v5_0_5_0.System
            };

            var compilation = CreateCompilation(
                new[] { Parse("") },
                references,
                options: TestOptions.ReleaseDll.WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default));

            compilation.VerifyDiagnostics(
                // error CS1703: Multiple assemblies with equivalent identity have been imported: 'System.dll' and 'System.v5.0.5.0_silverlight.dll'. Remove one of the duplicate references.
                Diagnostic(ErrorCode.ERR_DuplicateImport).WithArguments("System.dll", "System.v5.0.5.0_silverlight.dll"));

            var appConfig = new MemoryStream(Encoding.UTF8.GetBytes(
            @"<?xml version=""1.0"" encoding=""utf-8"" ?>
            <configuration>
              <runtime>
            <assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">
               <supportPortability PKT=""7cec85d7bea7798e"" enable=""false""/>
            </assemblyBinding>
              </runtime>
            </configuration>"));

            var comparer = DesktopAssemblyIdentityComparer.LoadFromXml(appConfig);

            compilation = CreateCompilation(
                new[] { Parse("") },
                references,
                options: TestOptions.ReleaseDll.WithAssemblyIdentityComparer(comparer));

            compilation.VerifyDiagnostics();
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:37,代码来源:CompilationAPITests.cs


示例12: TestMixedEventAccessorModifiers_EmptyConcrete

        public void TestMixedEventAccessorModifiers_EmptyConcrete()
        {
            var text1 = @"
class Derived : AccessorModifierMismatch
{
    // Not overriding anything.
}
";
            var refs = new MetadataReference[] { TestReferences.SymbolsTests.Events };
            CreateCompilationWithMscorlib(text1, references: refs, compOptions: TestOptions.Dll).VerifyDiagnostics(
                // (2,7): error CS0534: 'Derived' does not implement inherited abstract member 'AccessorModifierMismatch.NoneAbstract.remove'
                // class Derived : AccessorModifierMismatch
                Diagnostic(ErrorCode.ERR_UnimplementedAbstractMethod, "Derived").WithArguments("Derived", "AccessorModifierMismatch.NoneAbstract.remove"),
                // (2,7): error CS0534: 'Derived' does not implement inherited abstract member 'AccessorModifierMismatch.AbstractNone.add'
                // class Derived : AccessorModifierMismatch
                Diagnostic(ErrorCode.ERR_UnimplementedAbstractMethod, "Derived").WithArguments("Derived", "AccessorModifierMismatch.AbstractNone.add"));
        }
开发者ID:nagyist,项目名称:roslyn,代码行数:17,代码来源:OverriddenOrHiddenMembersTests.cs


示例13: TestMixedPropertyAccessorModifiers_OverrideSetters

        public void TestMixedPropertyAccessorModifiers_OverrideSetters()
        {
            var text1 = @"
class Derived : AccessorModifierMismatch // CS0534 (didn't implement AbstractAbstract.get)
{
    public override int NoneNone { set { } } // CS0506 (not virtual)
    public override int NoneAbstract { set { } }
    public override int NoneVirtual { set { } }
    public override int NoneOverride { set { } } // CS1545 (bogus)
    public override int NoneSealed { set { } } // CS1545 (bogus)

    public override int AbstractNone { set { } } // CS0506 (not virtual)
    public override int AbstractAbstract { set { } }
    public override int AbstractVirtual { set { } }
    public override int AbstractOverride { set { } } // CS1545 (bogus)
    public override int AbstractSealed { set { } } // CS1545 (bogus)

    public override int VirtualNone { set { } }
    public override int VirtualAbstract { set { } }
    public override int VirtualVirtual { set { } }
    public override int VirtualOverride { set { } } // CS1545 (bogus)
    public override int VirtualSealed { set { } } // CS1545 (bogus)

    public override int OverrideNone { set { } } // CS1545 (bogus)
    public override int OverrideAbstract { set { } } // CS1545 (bogus)
    public override int OverrideVirtual { set { } } // CS1545 (bogus)
    public override int OverrideOverride { set { } }
    public override int OverrideSealed { set { } } // CS1545 (bogus)

    public override int SealedNone { set { } } // CS1545 (bogus)
    public override int SealedAbstract { set { } } // CS1545 (bogus)
    public override int SealedVirtual { set { } } // CS1545 (bogus)
    public override int SealedOverride { set { } } // CS1545 (bogus)
    public override int SealedSealed { set { } } // CS0239 (sealed)
}
";
            var refs = new MetadataReference[] { TestReferences.SymbolsTests.Properties };
            CreateCompilationWithMscorlib(text1, references: refs, compOptions: TestOptions.Dll).VerifyDiagnostics(
                // (4,25): error CS0506: 'Derived.NoneNone': cannot override inherited member 'AccessorModifierMismatch.NoneNone' because it is not marked virtual, abstract, or override
                //     public override int NoneNone { set { } } // CS0506 (not virtual)
                Diagnostic(ErrorCode.ERR_CantOverrideNonVirtual, "NoneNone").WithArguments("Derived.NoneNone", "AccessorModifierMismatch.NoneNone"),
                // (7,25): error CS0569: 'Derived.NoneOverride': cannot override 'AccessorModifierMismatch.NoneOverride' because it is not supported by the language
                //     public override int NoneOverride { set { } } // CS1545 (bogus)
                Diagnostic(ErrorCode.ERR_CantOverrideBogusMethod, "NoneOverride").WithArguments("Derived.NoneOverride", "AccessorModifierMismatch.NoneOverride"),
                // (8,25): error CS0569: 'Derived.NoneSealed': cannot override 'AccessorModifierMismatch.NoneSealed' because it is not supported by the language
                //     public override int NoneSealed { set { } } // CS1545 (bogus)
                Diagnostic(ErrorCode.ERR_CantOverrideBogusMethod, "NoneSealed").WithArguments("Derived.NoneSealed", "AccessorModifierMismatch.NoneSealed"),
                // (10,40): error CS0506: 'Derived.AbstractNone.set': cannot override inherited member 'AccessorModifierMismatch.NoneNone.set' because it is not marked virtual, abstract, or override
                //     public override int AbstractNone { set { } } // CS0506 (not virtual)
                Diagnostic(ErrorCode.ERR_CantOverrideNonVirtual, "set").WithArguments("Derived.AbstractNone.set", "AccessorModifierMismatch.NoneNone.set"),
                // (13,25): error CS0569: 'Derived.AbstractOverride': cannot override 'AccessorModifierMismatch.AbstractOverride' because it is not supported by the language
                //     public override int AbstractOverride { set { } } // CS1545 (bogus)
                Diagnostic(ErrorCode.ERR_CantOverrideBogusMethod, "AbstractOverride").WithArguments("Derived.AbstractOverride", "AccessorModifierMismatch.AbstractOverride"),
                // (14,25): error CS0569: 'Derived.AbstractSealed': cannot override 'AccessorModifierMismatch.AbstractSealed' because it is not supported by the language
                //     public override int AbstractSealed { set { } } // CS1545 (bogus)
                Diagnostic(ErrorCode.ERR_CantOverrideBogusMethod, "AbstractSealed").WithArguments("Derived.AbstractSealed", "AccessorModifierMismatch.AbstractSealed"),
                // (16,39): error CS0506: 'Derived.VirtualNone.set': cannot override inherited member 'AccessorModifierMismatch.NoneNone.set' because it is not marked virtual, abstract, or override
                //     public override int VirtualNone { set { } }
                Diagnostic(ErrorCode.ERR_CantOverrideNonVirtual, "set").WithArguments("Derived.VirtualNone.set", "AccessorModifierMismatch.NoneNone.set"),
                // (19,25): error CS0569: 'Derived.VirtualOverride': cannot override 'AccessorModifierMismatch.VirtualOverride' because it is not supported by the language
                //     public override int VirtualOverride { set { } } // CS1545 (bogus)
                Diagnostic(ErrorCode.ERR_CantOverrideBogusMethod, "VirtualOverride").WithArguments("Derived.VirtualOverride", "AccessorModifierMismatch.VirtualOverride"),
                // (20,25): error CS0569: 'Derived.VirtualSealed': cannot override 'AccessorModifierMismatch.VirtualSealed' because it is not supported by the language
                //     public override int VirtualSealed { set { } } // CS1545 (bogus)
                Diagnostic(ErrorCode.ERR_CantOverrideBogusMethod, "VirtualSealed").WithArguments("Derived.VirtualSealed", "AccessorModifierMismatch.VirtualSealed"),
                // (22,25): error CS0569: 'Derived.OverrideNone': cannot override 'AccessorModifierMismatch.OverrideNone' because it is not supported by the language
                //     public override int OverrideNone { set { } } // CS1545 (bogus)
                Diagnostic(ErrorCode.ERR_CantOverrideBogusMethod, "OverrideNone").WithArguments("Derived.OverrideNone", "AccessorModifierMismatch.OverrideNone"),
                // (23,25): error CS0569: 'Derived.OverrideAbstract': cannot override 'AccessorModifierMismatch.OverrideAbstract' because it is not supported by the language
                //     public override int OverrideAbstract { set { } } // CS1545 (bogus)
                Diagnostic(ErrorCode.ERR_CantOverrideBogusMethod, "OverrideAbstract").WithArguments("Derived.OverrideAbstract", "AccessorModifierMismatch.OverrideAbstract"),
                // (24,25): error CS0569: 'Derived.OverrideVirtual': cannot override 'AccessorModifierMismatch.OverrideVirtual' because it is not supported by the language
                //     public override int OverrideVirtual { set { } } // CS1545 (bogus)
                Diagnostic(ErrorCode.ERR_CantOverrideBogusMethod, "OverrideVirtual").WithArguments("Derived.OverrideVirtual", "AccessorModifierMismatch.OverrideVirtual"),
                // (26,25): error CS0569: 'Derived.OverrideSealed': cannot override 'AccessorModifierMismatch.OverrideSealed' because it is not supported by the language
                //     public override int OverrideSealed { set { } } // CS1545 (bogus)
                Diagnostic(ErrorCode.ERR_CantOverrideBogusMethod, "OverrideSealed").WithArguments("Derived.OverrideSealed", "AccessorModifierMismatch.OverrideSealed"),
                // (28,25): error CS0569: 'Derived.SealedNone': cannot override 'AccessorModifierMismatch.SealedNone' because it is not supported by the language
                //     public override int SealedNone { set { } } // CS1545 (bogus)
                Diagnostic(ErrorCode.ERR_CantOverrideBogusMethod, "SealedNone").WithArguments("Derived.SealedNone", "AccessorModifierMismatch.SealedNone"),
                // (29,25): error CS0569: 'Derived.SealedAbstract': cannot override 'AccessorModifierMismatch.SealedAbstract' because it is not supported by the language
                //     public override int SealedAbstract { set { } } // CS1545 (bogus)
                Diagnostic(ErrorCode.ERR_CantOverrideBogusMethod, "SealedAbstract").WithArguments("Derived.SealedAbstract", "AccessorModifierMismatch.SealedAbstract"),
                // (30,25): error CS0569: 'Derived.SealedVirtual': cannot override 'AccessorModifierMismatch.SealedVirtual' because it is not supported by the language
                //     public override int SealedVirtual { set { } } // CS1545 (bogus)
                Diagnostic(ErrorCode.ERR_CantOverrideBogusMethod, "SealedVirtual").WithArguments("Derived.SealedVirtual", "AccessorModifierMismatch.SealedVirtual"),
                // (31,25): error CS0569: 'Derived.SealedOverride': cannot override 'AccessorModifierMismatch.SealedOverride' because it is not supported by the language
                //     public override int SealedOverride { set { } } // CS1545 (bogus)
                Diagnostic(ErrorCode.ERR_CantOverrideBogusMethod, "SealedOverride").WithArguments("Derived.SealedOverride", "AccessorModifierMismatch.SealedOverride"),
                // (32,25): error CS0239: 'Derived.SealedSealed': cannot override inherited member 'AccessorModifierMismatch.SealedSealed' because it is sealed
                //     public override int SealedSealed { set { } } // CS0239 (sealed)
                Diagnostic(ErrorCode.ERR_CantOverrideSealed, "SealedSealed").WithArguments("Derived.SealedSealed", "AccessorModifierMismatch.SealedSealed"),
                // (2,7): error CS0534: 'Derived' does not implement inherited abstract member 'AccessorModifierMismatch.AbstractNone.get'
                // class Derived : AccessorModifierMismatch // CS0534 (didn't implement AbstractAbstract.get)
                Diagnostic(ErrorCode.ERR_UnimplementedAbstractMethod, "Derived").WithArguments("Derived", "AccessorModifierMismatch.AbstractNone.get"));
        }
开发者ID:nagyist,项目名称:roslyn,代码行数:96,代码来源:OverriddenOrHiddenMembersTests.cs


示例14: TestMixedPropertyAccessorModifiers_EmptyAbstract

        public void TestMixedPropertyAccessorModifiers_EmptyAbstract()
        {
            var text1 = @"
abstract class Derived : AccessorModifierMismatch
{
    // Not overriding anything.
}
";
            var refs = new MetadataReference[] { TestReferences.SymbolsTests.Properties };
            CreateCompilationWithMscorlib(text1, references: refs, compOptions: TestOptions.Dll).VerifyDiagnostics();
        }
开发者ID:nagyist,项目名称:roslyn,代码行数:11,代码来源:OverriddenOrHiddenMembersTests.cs


示例15: SerializeMetadataReference

 public void SerializeMetadataReference(MetadataReference reference, ObjectWriter writer, CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     _hostSerializationService.WriteTo(reference, writer, cancellationToken);
 }
开发者ID:jkotas,项目名称:roslyn,代码行数:5,代码来源:Serializer_Asset.cs


示例16: GetAssemblyOrModuleSymbol

        /// <summary>
        /// Gets the <see cref="AssemblySymbol"/> or <see cref="ModuleSymbol"/> for a metadata reference used to create this compilation.
        /// </summary>
        /// <returns><see cref="AssemblySymbol"/> or <see cref="ModuleSymbol"/> corresponding to the given reference or null if there is none.</returns>
        /// <remarks>
        /// Uses object identity when comparing two references. 
        /// </remarks>
        internal new Symbol GetAssemblyOrModuleSymbol(MetadataReference reference)
        {
            if (reference == null)
            {
                throw new ArgumentNullException("reference");
            }

            if (reference.Properties.Kind == MetadataImageKind.Assembly)
            {
                return GetBoundReferenceManager().GetReferencedAssemblySymbol(reference);
            }
            else
            {
                Debug.Assert(reference.Properties.Kind == MetadataImageKind.Module);
                int index = GetBoundReferenceManager().GetReferencedModuleIndex(reference);
                return index < 0 ? null : this.Assembly.Modules[index];
            }
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:25,代码来源:CSharpCompilation.cs


示例17: GetMetadata

 private Metadata GetMetadata(MetadataReference mref)
 {
     var fnGetMetadata = mref.GetType().GetMethod("GetMetadata", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
     return fnGetMetadata?.Invoke(mref, null) as Metadata;
 }
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:5,代码来源:MSBuildWorkspaceTests.cs


示例18: return

 Compilation ICompilationFactoryService.GetCompilationFromCompilationReference(MetadataReference reference)
 {
     var compilationRef = reference as CompilationReference;
     return (compilationRef != null) ? compilationRef.Compilation : null;
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:5,代码来源:CSharpCompilationFactoryService.cs


示例19: Dump

        private string Dump(MetadataReference winmd, MetadataReference[] additionalRefs = null)
        {
            IEnumerable<MetadataReference> references = new[] { MscorlibRef_v4_0_30316_17626, _systemRuntimeRef, _systemObjectModelRef, _windowsRuntimeUIXamlRef, _interopServicesWindowsRuntimeRef, winmd };

            if (additionalRefs != null)
            {
                references = references.Concat(additionalRefs);
            }

            var comp = CreateCompilation("", references, options: TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.All));

            var writer = new StringBuilder();
            AppendAssemblyRefs(writer, (PEAssemblySymbol)comp.GetReferencedAssemblySymbol(winmd));

            AppendMembers(writer, comp.GetReferencedAssemblySymbol(winmd).GlobalNamespace, "");
            return writer.ToString();
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:17,代码来源:WinMdDumpTest.cs


示例20: Bug611578


//.........这里部分代码省略.........
    public void Fire01(ref bool arg, int idx = 0)
    {
        EventDelegate01 e = GetEventHandlerDelegate(idx) as EventDelegate01;
        if (null != e)
            e(ref arg);
    }

    public string Fire02(string arg, int idx = 1)
    {
        EventDelegate02 e = GetEventHandlerDelegate(idx) as EventDelegate02;
        if (null != e)
            return e(arg);
        return String.Empty;
    }

    #endregion
}
";

            System.Action<ModuleSymbol> metadataValidator =
                delegate (ModuleSymbol module)
                {
                    ((PEModuleSymbol)module).Module.PretendThereArentNoPiaLocalTypes();

                    var IEventsBase = (PENamedTypeSymbol)module.GlobalNamespace.GetTypeMembers("IEventsBase").Single();
                    Assert.Equal(1, IEventsBase.GetMembers("MyEvent01").Length);
                };

            var NetImpl_1_Compilation = CreateCompilationWithMscorlib(NetImpl_cs, new[] { new CSharpCompilationReference(IEvent_Compilation, embedInteropTypes: true) }, options: TestOptions.ReleaseDll, assemblyName: "NetImpl");

            CompileAndVerify(NetImpl_1_Compilation, symbolValidator: metadataValidator);
            var NetImpl_1_Image = NetImpl_1_Compilation.EmitToStream();

            var NetImpl_2_Compilation = CreateCompilationWithMscorlib(NetImpl_cs, new[] { IEvent_Metadata.GetReference(embedInteropTypes: true) }, options: TestOptions.ReleaseDll, assemblyName: "NetImpl");

            CompileAndVerify(NetImpl_2_Compilation, symbolValidator: metadataValidator);
            var NetImpl_2_Image = NetImpl_2_Compilation.EmitToStream();

            string App_cs = @"
using System;

class Test
{
    public static void Main()
    {
        var obj = new NetImpl();
        var d1 = false;
        dynamic d2 = ""123"";
        // cast to interface
        IEventsDerived_Event iobj = obj;

        // Event 1
        iobj.MyEvent01 += new EventDelegate01(MyEvent01Handler);
        obj.Fire01(ref d1);

        // Event 2
        iobj.MyEvent02 += new EventDelegate02(MyEvent02Handler);
        obj.Fire02(d2);
    }

    #region Event Handlers

    static void MyEvent01Handler(ref bool arg)
    {
        Console.WriteLine(""E01"");
        arg = true;
    }

    static string MyEvent02Handler(string arg)
    {
        Console.WriteLine(""E02"");
        return arg;
    }

    #endregion
}
";

            MetadataReference[] NetImpl_refs = new MetadataReference[] { new CSharpCompilationReference(NetImpl_1_Compilation),
                                                                         new CSharpCompilationReference(NetImpl_2_Compilation),
                                                                         MetadataReference.CreateFromStream(NetImpl_1_Image),
                                                                         MetadataReference.CreateFromStream(NetImpl_2_Image)};

            MetadataReference[] IEvent_refs = new MetadataReference[] { new CSharpCompilationReference(IEvent_Compilation),
                                                                        new CSharpCompilationReference(IEvent_Compilation, embedInteropTypes: true),
                                                                        IEvent_Metadata.GetReference(),
                                                                        IEvent_Metadata.GetReference(embedInteropTypes: true)};

            foreach (var NetImpl_ref in NetImpl_refs)
            {
                foreach (var IEvent_ref in IEvent_refs)
                {
                    var app_compilation = CreateCompilationWithMscorlib(App_cs, new[] { NetImpl_ref, IEvent_ref, CSharpRef, SystemCoreRef }, options: TestOptions.ReleaseExe, assemblyName: "App");

                    CompileAndVerify(app_compilation, symbolValidator: IEvent_ref.Properties.EmbedInteropTypes ? metadataValidator : null,
                        expectedOutput: @"E01
E02");
                }
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:101,代码来源:NoPiaEmbedTypes.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# MetadataReferenceProperties类代码示例发布时间:2022-05-24
下一篇:
C# MetadataReader类代码示例发布时间: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