本文整理汇总了C#中Microsoft.CodeAnalysis.MetadataReferenceResolver.ResolveReference方法的典型用法代码示例。如果您正苦于以下问题:C# MetadataReferenceResolver.ResolveReference方法的具体用法?C# MetadataReferenceResolver.ResolveReference怎么用?C# MetadataReferenceResolver.ResolveReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.MetadataReferenceResolver
的用法示例。
在下文中一共展示了MetadataReferenceResolver.ResolveReference方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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);
}
}