本文整理汇总了C#中SemanticModel.GetSemanticInfo方法的典型用法代码示例。如果您正苦于以下问题:C# SemanticModel.GetSemanticInfo方法的具体用法?C# SemanticModel.GetSemanticInfo怎么用?C# SemanticModel.GetSemanticInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SemanticModel
的用法示例。
在下文中一共展示了SemanticModel.GetSemanticInfo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSymbolsTouchingPosition
internal static IEnumerable<ISymbol> GetSymbolsTouchingPosition(
int position, SemanticModel semanticModel, Workspace workspace, CancellationToken cancellationToken)
{
var bindableToken = semanticModel.SyntaxTree.GetRoot(cancellationToken).FindToken(position, findInsideTrivia: true);
var semanticInfo = semanticModel.GetSemanticInfo(bindableToken, workspace, cancellationToken);
var symbols = semanticInfo.DeclaredSymbol != null
? ImmutableArray.Create<ISymbol>(semanticInfo.DeclaredSymbol)
: semanticInfo.GetSymbols(includeType: false);
// if there are more than one symbol, then remove the alias symbols.
// When using (not declaring) an alias, the alias symbol and the target symbol are returned
// by GetSymbols
if (symbols.Length > 1)
{
symbols = symbols.WhereAsArray(s => s.Kind != SymbolKind.Alias);
}
if (symbols.Length == 0)
{
var info = semanticModel.GetSymbolInfo(bindableToken, cancellationToken);
if (info.CandidateReason == CandidateReason.MemberGroup)
{
return info.CandidateSymbols;
}
}
return symbols;
}