當前位置: 首頁>>代碼示例>>C#>>正文


C# CodeAnalysis.MetadataReferenceResolver類代碼示例

本文整理匯總了C#中Microsoft.CodeAnalysis.MetadataReferenceResolver的典型用法代碼示例。如果您正苦於以下問題:C# MetadataReferenceResolver類的具體用法?C# MetadataReferenceResolver怎麽用?C# MetadataReferenceResolver使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MetadataReferenceResolver類屬於Microsoft.CodeAnalysis命名空間,在下文中一共展示了MetadataReferenceResolver類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ResolveMetadataReferences

        /// <summary>
        /// Resolves metadata references stored in command line arguments and reports errors for those that can't be resolved.
        /// </summary>
        internal List<MetadataReference> ResolveMetadataReferences(
            List<DiagnosticInfo> diagnostics,
            TouchedFileLogger touchedFiles,
            out MetadataReferenceResolver referenceDirectiveResolver)
        {
            var commandLineReferenceResolver = GetCommandLineMetadataReferenceResolver(touchedFiles);

            List<MetadataReference> resolved = new List<MetadataReference>();
            Arguments.ResolveMetadataReferences(commandLineReferenceResolver, diagnostics, this.MessageProvider, resolved);

            if (Arguments.IsScriptRunner)
            {
                referenceDirectiveResolver = commandLineReferenceResolver;
            }
            else
            {
                // when compiling into an assembly (csc/vbc) we only allow #r that match references given on command line:
                referenceDirectiveResolver = new ExistingReferencesResolver(commandLineReferenceResolver, resolved.ToImmutableArray());
            }

            return resolved;
        }
開發者ID:SoumikMukherjeeDOTNET,項目名稱:roslyn,代碼行數:25,代碼來源:CommonCompiler.cs

示例2: CompilationOptions

        // Expects correct arguments.
        internal CompilationOptions(
            OutputKind outputKind,
            bool reportSuppressedDiagnostics,
            string moduleName,
            string mainTypeName,
            string scriptClassName,
            string cryptoKeyContainer,
            string cryptoKeyFile,
            ImmutableArray<byte> cryptoPublicKey,
            bool? delaySign,
            OptimizationLevel optimizationLevel,
            bool checkOverflow,
            Platform platform,
            ReportDiagnostic generalDiagnosticOption,
            int warningLevel,
            ImmutableDictionary<string, ReportDiagnostic> specificDiagnosticOptions,
            bool concurrentBuild,
            bool extendedCustomDebugInformation,
            bool debugPlusMode,
            XmlReferenceResolver xmlReferenceResolver,
            SourceReferenceResolver sourceReferenceResolver,
            MetadataReferenceResolver metadataReferenceResolver,
            AssemblyIdentityComparer assemblyIdentityComparer,
            StrongNameProvider strongNameProvider,
            MetadataImportOptions metadataImportOptions)
        {
            this.OutputKind = outputKind;
            this.ModuleName = moduleName;
            this.MainTypeName = mainTypeName;
            this.ScriptClassName = scriptClassName ?? WellKnownMemberNames.DefaultScriptClassName;
            this.CryptoKeyContainer = cryptoKeyContainer;
            this.CryptoKeyFile = cryptoKeyFile;
            this.CryptoPublicKey = cryptoPublicKey.NullToEmpty();
            this.DelaySign = delaySign;
            this.CheckOverflow = checkOverflow;
            this.Platform = platform;
            this.GeneralDiagnosticOption = generalDiagnosticOption;
            this.WarningLevel = warningLevel;
            this.SpecificDiagnosticOptions = specificDiagnosticOptions;
            this.ReportSuppressedDiagnostics = reportSuppressedDiagnostics;
            this.OptimizationLevel = optimizationLevel;
            this.ConcurrentBuild = concurrentBuild;
            this.ExtendedCustomDebugInformation = extendedCustomDebugInformation;
            this.DebugPlusMode = debugPlusMode;
            this.XmlReferenceResolver = xmlReferenceResolver;
            this.SourceReferenceResolver = sourceReferenceResolver;
            this.MetadataReferenceResolver = metadataReferenceResolver;
            this.StrongNameProvider = strongNameProvider;
            this.AssemblyIdentityComparer = assemblyIdentityComparer ?? AssemblyIdentityComparer.Default;
            this.MetadataImportOptions = metadataImportOptions;

            _lazyErrors = new Lazy<ImmutableArray<Diagnostic>>(() =>
            {
                var builder = ArrayBuilder<Diagnostic>.GetInstance();
                ValidateOptions(builder);
                return builder.ToImmutableAndFree();
            });
        }
開發者ID:nemec,項目名稱:roslyn,代碼行數:59,代碼來源:CompilationOptions.cs

示例3: ResolveMetadataReferences

        internal virtual bool ResolveMetadataReferences(MetadataReferenceResolver metadataResolver, List<DiagnosticInfo> diagnosticsOpt, CommonMessageProvider messageProviderOpt, List<MetadataReference> resolved)
        {
            bool result = true;

            foreach (CommandLineReference cmdReference in MetadataReferences)
            {
                var references = ResolveMetadataReference(cmdReference, metadataResolver, diagnosticsOpt, messageProviderOpt);
                if (!references.IsDefaultOrEmpty)
                {
                    resolved.AddRange(references);
                }
                else
                {
                    result = false;
                    if (diagnosticsOpt == null)
                    {
                        // no diagnostic, so leaved unresolved reference in list
                        resolved.Add(new UnresolvedMetadataReference(cmdReference.Reference, cmdReference.Properties));
                    }
                }
            }

            return result;
        }
開發者ID:abock,項目名稱:roslyn,代碼行數:24,代碼來源:CommonCommandLineArguments.cs

示例4: ResolveMetadataReference

        internal static ImmutableArray<PortableExecutableReference> ResolveMetadataReference(CommandLineReference cmdReference, MetadataReferenceResolver metadataResolver, List<DiagnosticInfo> diagnosticsOpt, CommonMessageProvider messageProviderOpt)
        {
            Debug.Assert(metadataResolver != null);
            Debug.Assert((diagnosticsOpt == null) == (messageProviderOpt == null));

            ImmutableArray<PortableExecutableReference> references;
            try
            {
                references = metadataResolver.ResolveReference(cmdReference.Reference, baseFilePath: null, properties: cmdReference.Properties);
            }
            catch (Exception e) when (diagnosticsOpt != null && (e is BadImageFormatException || e is IOException))
            {
                var diagnostic = PortableExecutableReference.ExceptionToDiagnostic(e, messageProviderOpt, Location.None, cmdReference.Reference, cmdReference.Properties.Kind);
                diagnosticsOpt.Add(((DiagnosticWithInfo)diagnostic).Info);
                return ImmutableArray<PortableExecutableReference>.Empty;
            }

            if (references.IsDefaultOrEmpty && diagnosticsOpt != null)
            {
                diagnosticsOpt.Add(new DiagnosticInfo(messageProviderOpt, messageProviderOpt.ERR_MetadataFileNotFound, cmdReference.Reference));
                return ImmutableArray<PortableExecutableReference>.Empty;
            }

            return references;
        }
開發者ID:abock,項目名稱:roslyn,代碼行數:25,代碼來源:CommonCommandLineArguments.cs

示例5: CreateAssemblyFromIdentity

            PEAssemblySymbol CreateAssemblyFromIdentity(MetadataReferenceResolver resolver, AssemblyIdentity identity, string basePath, List<PEModuleSymbol> modules)
            {
                PEAssemblySymbol ass;
                if (!_assembliesMap.TryGetValue(identity, out ass))
                {
                    // temporary: lookup ignoring minor version number
                    foreach (var pair in _assembliesMap)
                    {
                        if (pair.Key.Name.Equals(identity.Name, StringComparison.OrdinalIgnoreCase) && pair.Key.Version.Major == identity.Version.Major)
                        {
                            _assembliesMap[identity] = pair.Value;
                            return pair.Value;
                        }
                    }

                    //
                    string keytoken = string.Join("", identity.PublicKeyToken.Select(b => b.ToString("x2")));
                    var pes = resolver.ResolveReference(identity.Name + ".dll", basePath, MetadataReferenceProperties.Assembly)
                        .Concat(resolver.ResolveReference($"{identity.Name}/v4.0_{identity.Version}__{keytoken}/{identity.Name}.dll", basePath, MetadataReferenceProperties.Assembly));

                    var pe = pes.FirstOrDefault();
                    if (pe != null)
                    {
                        _assembliesMap[identity] = ass = PEAssemblySymbol.Create(pe);
                        ass.SetCorLibrary(_lazyCorLibrary);
                        modules.AddRange(ass.Modules.Cast<PEModuleSymbol>());
                    }
                    else
                    {
                        throw new DllNotFoundException(identity.GetDisplayName());
                    }
                }

                return ass;
            }
開發者ID:iolevel,項目名稱:peachpie,代碼行數:35,代碼來源:ReferenceManager.cs

示例6: ResolveMetadataReferences

        /// <summary>
        /// Resolves metadata references stored in <see cref="MetadataReferences"/> using given file resolver and metadata provider.
        /// If a non-null diagnostic bag <paramref name="diagnosticsOpt"/> is provided, it catches exceptions that may be generated while reading the metadata file and
        /// reports appropriate diagnostics.
        /// Otherwise, if <paramref name="diagnosticsOpt"/> is null, the exceptions are unhandled.
        /// </summary>
        internal IEnumerable<MetadataReference> ResolveMetadataReferences(MetadataReferenceResolver metadataResolver, MetadataReferenceProvider metadataProvider, List<DiagnosticInfo> diagnosticsOpt, CommonMessageProvider messageProviderOpt)
        {
            Debug.Assert(metadataResolver != null);
            Debug.Assert(metadataProvider != null);

            foreach (CommandLineReference cmdReference in MetadataReferences)
            {
                yield return ResolveMetadataReference(cmdReference, metadataResolver, metadataProvider, diagnosticsOpt, messageProviderOpt) ?? 
                    new UnresolvedMetadataReference(cmdReference.Reference, cmdReference.Properties);
            }
        }
開發者ID:riversky,項目名稱:roslyn,代碼行數:17,代碼來源:CommonCommandLineArguments.cs

示例7: ResolveMetadataReferences

        /// <summary>
        /// Resolves metadata references stored in command line arguments and reports errors for those that can't be resolved.
        /// </summary>
        internal List<MetadataReference> ResolveMetadataReferences(
            MetadataReferenceResolver externalReferenceResolver,
            MetadataReferenceProvider metadataProvider,
            List<DiagnosticInfo> diagnostics,
            AssemblyIdentityComparer assemblyIdentityComparer,
            TouchedFileLogger touchedFiles,
            out MetadataReferenceResolver referenceDirectiveResolver)
        {
            using (Logger.LogBlock(FunctionId.Common_CommandLineCompiler_ResolveMetadataReferences))
            {
                List<MetadataReference> resolved = new List<MetadataReference>();
                ResolveMetadataReferencesFromArguments(externalReferenceResolver, metadataProvider, diagnostics, resolved);

                if (Arguments.IsInteractive)
                {
                    referenceDirectiveResolver = externalReferenceResolver;
                }
                else
                {
                    // when compiling into an assembly (csc/vbc) we only allow #r that match references given on command line:
                    referenceDirectiveResolver = new ExistingReferencesResolver(
                        resolved.Where(r => r.Properties.Kind == MetadataImageKind.Assembly).OfType<MetadataFileReference>().AsImmutable(),
                        Arguments.ReferencePaths,
                        Arguments.BaseDirectory,
                        assemblyIdentityComparer,
                        touchedFiles);
                }

                return resolved;
            }
        }
開發者ID:riversky,項目名稱:roslyn,代碼行數:34,代碼來源:CommonCompiler.cs

示例8: SetReferencesOfReferencedModules

            void SetReferencesOfReferencedModules(MetadataReferenceResolver resolver, List<PEModuleSymbol> modules)
            {
                for (int i = 0; i < modules.Count; i++)
                {
                    var refs = modules[i].Module.ReferencedAssemblies;
                    var symbols = new AssemblySymbol[refs.Length];
                    
                    for (int j = 0; j < refs.Length; j++)
                    {
                        var symbol = CreateAssemblyFromIdentity(resolver, refs[j], null, modules);
                        symbols[j] = symbol;
                    }

                    //
                    modules[i].SetReferences(new ModuleReferences<AssemblySymbol>(refs, symbols.AsImmutable(), ImmutableArray<UnifiedAssembly<AssemblySymbol>>.Empty));
                }
            }
開發者ID:iolevel,項目名稱:peachpie,代碼行數:17,代碼來源:ReferenceManager.cs

示例9: ResolveMetadataReferencesFromArguments

        /// <summary>
        /// Returns false if there were unresolved references in arguments, true otherwise.
        /// </summary>
        protected virtual bool ResolveMetadataReferencesFromArguments(MetadataReferenceResolver externalReferenceResolver, MetadataReferenceProvider metadataProvider, List<DiagnosticInfo> diagnostics, List<MetadataReference> resolved)
        {
            bool result = true;

            foreach (var reference in Arguments.ResolveMetadataReferences(externalReferenceResolver, metadataProvider, diagnostics, MessageProvider))
            {
                if (!reference.IsUnresolved)
                {
                    resolved.Add(reference);
                }
                else
                {
                    result = false;
                    Debug.Assert(diagnostics.Any());
                }
            }

            return result;
        }
開發者ID:riversky,項目名稱:roslyn,代碼行數:22,代碼來源:CommonCompiler.cs

示例10: ResolveMetadataReference

        // TODO: change to private protected when available
        internal static MetadataReference ResolveMetadataReference(CommandLineReference cmdReference, MetadataReferenceResolver metadataResolver, MetadataReferenceProvider metadataProvider, List<DiagnosticInfo> diagnosticsOpt, CommonMessageProvider messageProviderOpt)
        {
            Debug.Assert(metadataResolver != null);
            Debug.Assert(metadataProvider != null);
            Debug.Assert((diagnosticsOpt == null) == (messageProviderOpt == null));

            string resolvedPath = metadataResolver.ResolveReference(cmdReference.Reference, baseFilePath: null);
            if (resolvedPath == null)
            {
                if (diagnosticsOpt != null)
                {
                    diagnosticsOpt.Add(new DiagnosticInfo(messageProviderOpt, messageProviderOpt.ERR_MetadataFileNotFound, cmdReference.Reference));
                }

                return null;
            }

            try
            {
                return metadataProvider.GetReference(resolvedPath, cmdReference.Properties);
            }
            catch (Exception e) if (diagnosticsOpt != null && (e is BadImageFormatException || e is IOException))
            {
                var diagnostic = PortableExecutableReference.ExceptionToDiagnostic(e, messageProviderOpt, Location.None, cmdReference.Reference, cmdReference.Properties.Kind);
                diagnosticsOpt.Add(((DiagnosticWithInfo)diagnostic).Info);
                return null;
            }
        }

        #endregion

        #region Analyzer References

        /// <summary>
        /// Resolves analyzer references stored in <see cref="AnalyzerReferences"/> using given file resolver.
        /// </summary>
        /// <returns>Yields resolved <see cref="AnalyzerFileReference"/> or <see cref="UnresolvedAnalyzerReference"/>.</returns>
        public IEnumerable<AnalyzerReference> ResolveAnalyzerReferences()
        {
            foreach (CommandLineAnalyzerReference cmdLineReference in AnalyzerReferences)
            {
                yield return ResolveAnalyzerReference(cmdLineReference) 
                    ?? (AnalyzerReference)new UnresolvedAnalyzerReference(cmdLineReference.FilePath);
            }
        }
開發者ID:modulexcite,項目名稱:pattern-matching-csharp,代碼行數:46,代碼來源:CommonCommandLineArguments.cs

示例11: MetadataResolver

 public MetadataResolver(MetadataReferenceResolver previousResolver)
 {
     this.previousResolver = previousResolver;
 }
開發者ID:southpolenator,項目名稱:WinDbgCs,代碼行數:4,代碼來源:ScriptExecution.cs

示例12: WithMetadataReferenceResolver

 public CompilationOptions WithMetadataReferenceResolver(MetadataReferenceResolver resolver)
 {
     return CommonWithMetadataReferenceResolver(resolver);
 }
開發者ID:nemec,項目名稱:roslyn,代碼行數:4,代碼來源:CompilationOptions.cs

示例13: CompilationOptions

        // Expects correct arguments.
        internal CompilationOptions(
            OutputKind outputKind,
            string moduleName,
            string mainTypeName,
            string scriptClassName,
            string cryptoKeyContainer,
            string cryptoKeyFile,
            bool? delaySign,
            OptimizationLevel optimizationLevel,
            bool checkOverflow,
            int fileAlignment,
            ulong baseAddress,
            Platform platform,
            ReportDiagnostic generalDiagnosticOption,
            int warningLevel,
            ImmutableDictionary<string, ReportDiagnostic> specificDiagnosticOptions,
            bool highEntropyVirtualAddressSpace,
            SubsystemVersion subsystemVersion,
            bool concurrentBuild,
            XmlReferenceResolver xmlReferenceResolver,
            SourceReferenceResolver sourceReferenceResolver,
            MetadataReferenceResolver metadataReferenceResolver,
            MetadataReferenceProvider metadataReferenceProvider,
            AssemblyIdentityComparer assemblyIdentityComparer,
            StrongNameProvider strongNameProvider,
            MetadataImportOptions metadataImportOptions,
            ImmutableArray<string> features)
        {
            this.OutputKind = outputKind;
            this.ModuleName = moduleName;
            this.MainTypeName = mainTypeName;
            this.ScriptClassName = scriptClassName;
            this.CryptoKeyContainer = cryptoKeyContainer;
            this.CryptoKeyFile = cryptoKeyFile;
            this.DelaySign = delaySign;
            this.CheckOverflow = checkOverflow;
            this.FileAlignment = fileAlignment;
            this.BaseAddress = baseAddress;
            this.Platform = platform;
            this.GeneralDiagnosticOption = generalDiagnosticOption;
            this.WarningLevel = warningLevel;
            this.SpecificDiagnosticOptions = specificDiagnosticOptions;
            this.HighEntropyVirtualAddressSpace = highEntropyVirtualAddressSpace;
            this.OptimizationLevel = optimizationLevel;
            this.ConcurrentBuild = concurrentBuild;
            this.SubsystemVersion = subsystemVersion;
            this.XmlReferenceResolver = xmlReferenceResolver;
            this.SourceReferenceResolver = sourceReferenceResolver;
            this.MetadataReferenceResolver = metadataReferenceResolver;
            this.MetadataReferenceProvider = metadataReferenceProvider;
            this.StrongNameProvider = strongNameProvider;
            this.AssemblyIdentityComparer = assemblyIdentityComparer ?? AssemblyIdentityComparer.Default;
            this.MetadataImportOptions = metadataImportOptions;
            this.Features = features;

            this.lazyErrors = new Lazy<ImmutableArray<Diagnostic>>(() =>
            {
                var builder = ArrayBuilder<Diagnostic>.GetInstance();
                ValidateOptions(builder);
                return builder.ToImmutableAndFree();
            });
        }
開發者ID:modulexcite,項目名稱:pattern-matching-csharp,代碼行數:63,代碼來源:CompilationOptions.cs

示例14: CommonWithMetadataReferenceResolver

 protected abstract CompilationOptions CommonWithMetadataReferenceResolver(MetadataReferenceResolver resolver);
開發者ID:nemec,項目名稱:roslyn,代碼行數:1,代碼來源:CompilationOptions.cs

示例15: CompilationOptions

 // Expects correct arguments.
 internal CompilationOptions(
     OutputKind outputKind,
     string moduleName,
     string mainTypeName,
     string scriptClassName,
     string cryptoKeyContainer,
     string cryptoKeyFile,
     bool? delaySign,
     bool optimize,
     bool checkOverflow,
     int fileAlignment,
     ulong baseAddress,
     Platform platform,
     ReportDiagnostic generalDiagnosticOption,
     int warningLevel,
     IEnumerable<KeyValuePair<string, ReportDiagnostic>> specificDiagnosticOptions,
     bool highEntropyVirtualAddressSpace,
     DebugInformationKind debugInformationKind,
     SubsystemVersion subsystemVersion,
     bool concurrentBuild,
     XmlReferenceResolver xmlReferenceResolver,
     SourceReferenceResolver sourceReferenceResolver,
     MetadataReferenceResolver metadataReferenceResolver,
     MetadataReferenceProvider metadataReferenceProvider,
     AssemblyIdentityComparer assemblyIdentityComparer,
     StrongNameProvider strongNameProvider,
     MetadataImportOptions metadataImportOptions)
 {
     Initialize(
         outputKind, moduleName, mainTypeName, scriptClassName, cryptoKeyContainer, cryptoKeyFile, delaySign, optimize, checkOverflow, fileAlignment, 
         baseAddress, platform, generalDiagnosticOption, warningLevel, specificDiagnosticOptions, highEntropyVirtualAddressSpace, debugInformationKind, 
         subsystemVersion, concurrentBuild, xmlReferenceResolver, sourceReferenceResolver, metadataReferenceResolver, metadataReferenceProvider, assemblyIdentityComparer, strongNameProvider, 
         metadataImportOptions);
 }
開發者ID:riversky,項目名稱:roslyn,代碼行數:35,代碼來源:CompilationOptions.cs


注:本文中的Microsoft.CodeAnalysis.MetadataReferenceResolver類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。