本文整理汇总了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;
}
示例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();
});
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
}
示例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));
}
}
示例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;
}
示例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);
}
}
示例11: MetadataResolver
public MetadataResolver(MetadataReferenceResolver previousResolver)
{
this.previousResolver = previousResolver;
}
示例12: WithMetadataReferenceResolver
public CompilationOptions WithMetadataReferenceResolver(MetadataReferenceResolver resolver)
{
return CommonWithMetadataReferenceResolver(resolver);
}
示例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();
});
}
示例14: CommonWithMetadataReferenceResolver
protected abstract CompilationOptions CommonWithMetadataReferenceResolver(MetadataReferenceResolver resolver);
示例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);
}