本文整理汇总了C#中Compilation.GetAssemblyOrModuleSymbol方法的典型用法代码示例。如果您正苦于以下问题:C# Compilation.GetAssemblyOrModuleSymbol方法的具体用法?C# Compilation.GetAssemblyOrModuleSymbol怎么用?C# Compilation.GetAssemblyOrModuleSymbol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compilation
的用法示例。
在下文中一共展示了Compilation.GetAssemblyOrModuleSymbol方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAssemblyDisplay
public static string GetAssemblyDisplay(Compilation compilation, IAssemblySymbol assemblySymbol)
{
// This method is only used to generate a comment at the top of Metadata-as-Source documents and
// previous submissions are never viewed as metadata (i.e. we always have compilations) so there's no
// need to consume compilation.ScriptCompilationInfo.PreviousScriptCompilation.
// TODO (https://github.com/dotnet/roslyn/issues/6859): compilation.GetMetadataReference(assemblySymbol)?
var assemblyReference = compilation.References.Where(r =>
{
var referencedSymbol = compilation.GetAssemblyOrModuleSymbol(r) as IAssemblySymbol;
return
referencedSymbol != null &&
referencedSymbol.MetadataName == assemblySymbol.MetadataName;
})
.FirstOrDefault();
return assemblyReference?.Display ?? FeaturesResources.location_unknown;
}
示例2: GetAssemblyDisplay
public static string GetAssemblyDisplay(Compilation compilation, IAssemblySymbol assemblySymbol)
{
var assemblyReference = compilation.References.Where(r =>
{
var referencedSymbol = compilation.GetAssemblyOrModuleSymbol(r) as IAssemblySymbol;
return
referencedSymbol != null &&
referencedSymbol.MetadataName == assemblySymbol.MetadataName;
})
.FirstOrDefault();
if (assemblyReference != null && assemblyReference.Display != null)
{
return assemblyReference.Display;
}
else
{
return FeaturesResources.LocationUnknown;
}
}
示例3: HasMissingReferences
private bool HasMissingReferences(Compilation compilation, IReadOnlyList<MetadataReference> metadataReferences)
{
foreach (var reference in metadataReferences)
{
if (compilation.GetAssemblyOrModuleSymbol(reference) == null)
{
return true;
}
}
return false;
}
示例4: UpdateCompilationWithNewReferencesAndRecordAssemblySymbols
private Compilation UpdateCompilationWithNewReferencesAndRecordAssemblySymbols(Compilation compilation, List<MetadataReference> newReferences, Dictionary<MetadataReference, ProjectId> metadataReferenceToProjectId)
{
if (!Enumerable.SequenceEqual(compilation.ExternalReferences, newReferences))
{
compilation = compilation.WithReferences(newReferences);
}
// TODO: Record source assembly to project mapping
// RecordSourceOfAssemblySymbol(compilation.Assembly, this.ProjectState.Id);
foreach (var kvp in metadataReferenceToProjectId)
{
var metadataReference = kvp.Key;
var projectId = kvp.Value;
var symbol = compilation.GetAssemblyOrModuleSymbol(metadataReference);
RecordSourceOfAssemblySymbol(symbol, projectId);
}
return compilation;
}
示例5: ResolveSymbolAsync
public async Task<ISymbol> ResolveSymbolAsync(string symbolMetadataName, Compilation compilation = null)
{
if (compilation == null)
{
compilation = await this.DefaultProject.GetCompilationAsync();
var diagnostics = compilation.GetDiagnostics().ToArray();
Assert.Equal(0, diagnostics.Length);
}
foreach (var reference in compilation.References)
{
var assemblySymbol = (IAssemblySymbol)compilation.GetAssemblyOrModuleSymbol(reference);
var namedTypeSymbol = assemblySymbol.GetTypeByMetadataName(symbolMetadataName);
if (namedTypeSymbol != null)
{
return namedTypeSymbol;
}
else
{
// The symbol name could possibly be referring to the member of a named
// type. Parse the member symbol name.
var lastDotIndex = symbolMetadataName.LastIndexOf('.');
if (lastDotIndex < 0)
{
// The symbol name is not a member name and the named type was not found
// in this assembly
continue;
}
// The member symbol name itself could contain a dot (e.g. '.ctor'), so make
// sure we don't cut that off
while (lastDotIndex > 0 && symbolMetadataName[lastDotIndex - 1] == '.')
{
--lastDotIndex;
}
var memberSymbolName = symbolMetadataName.Substring(lastDotIndex + 1);
var namedTypeName = symbolMetadataName.Substring(0, lastDotIndex);
namedTypeSymbol = assemblySymbol.GetTypeByMetadataName(namedTypeName);
if (namedTypeSymbol != null)
{
var memberSymbol = namedTypeSymbol.GetMembers()
.Where(member => member.MetadataName == memberSymbolName)
.FirstOrDefault();
if (memberSymbol != null)
{
return memberSymbol;
}
}
}
}
return null;
}
示例6: UpdateReferenceAsync
private async Task UpdateReferenceAsync(
Project project, Compilation compilation, PortableExecutableReference reference, CancellationToken cancellationToken)
{
var key = GetReferenceKey(reference);
if (key == null)
{
return;
}
DateTime lastWriteTime;
if (!TryGetLastWriteTime(key, out lastWriteTime))
{
// Couldn't get the write time. Just ignore this reference.
return;
}
MetadataInfo metadataInfo;
if (!_metadataPathToInfo.TryGetValue(key, out metadataInfo) || metadataInfo.TimeStamp == lastWriteTime)
{
var assembly = compilation.GetAssemblyOrModuleSymbol(reference) as IAssemblySymbol;
var info = assembly == null
? null
: await SymbolTreeInfo.TryGetInfoForMetadataAssemblyAsync(project.Solution, assembly, reference, loadOnly: false, cancellationToken: cancellationToken).ConfigureAwait(false);
metadataInfo = new MetadataInfo(lastWriteTime, info, metadataInfo.ReferencingProjects ?? new HashSet<ProjectId>());
_metadataPathToInfo.AddOrUpdate(key, metadataInfo, (_1, _2) => metadataInfo);
}
// Keep track that this dll is referenced by this project.
metadataInfo.ReferencingProjects.Add(project.Id);
}
示例7: GetAssembly
public IAssemblySymbol GetAssembly(Compilation compilation)
{
return compilation.GetAssemblyOrModuleSymbol(_reference) as IAssemblySymbol;
}