本文整理汇总了C#中Microsoft.CodeAnalysis.SemanticModel.GetSemanticInfo方法的典型用法代码示例。如果您正苦于以下问题:C# SemanticModel.GetSemanticInfo方法的具体用法?C# SemanticModel.GetSemanticInfo怎么用?C# SemanticModel.GetSemanticInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.SemanticModel
的用法示例。
在下文中一共展示了SemanticModel.GetSemanticInfo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryGetTextForSymbol
private bool TryGetTextForSymbol(SyntaxToken token, SemanticModel semanticModel, Document document, CancellationToken cancellationToken, out string text)
{
ISymbol symbol;
if (token.Parent is TypeArgumentListSyntax)
{
var genericName = token.GetAncestor<GenericNameSyntax>();
symbol = semanticModel.GetSymbolInfo(genericName, cancellationToken).Symbol ?? semanticModel.GetTypeInfo(genericName, cancellationToken).Type;
}
else if (token.Parent is NullableTypeSyntax && token.IsKind(SyntaxKind.QuestionToken))
{
text = "System.Nullable`1";
return true;
}
else
{
symbol = semanticModel.GetSemanticInfo(token, document.Project.Solution.Workspace, cancellationToken)
.GetAnySymbol(includeType: true);
if (symbol == null)
{
var bindableParent = document.GetLanguageService<ISyntaxFactsService>().GetBindableParent(token);
var overloads = semanticModel.GetMemberGroup(bindableParent);
symbol = overloads.FirstOrDefault();
}
}
// Local: return the name if it's the declaration, otherwise the type
if (symbol is ILocalSymbol && !symbol.DeclaringSyntaxReferences.Any(d => d.GetSyntax().DescendantTokens().Contains(token)))
{
symbol = ((ILocalSymbol)symbol).Type;
}
// Range variable: use the type
if (symbol is IRangeVariableSymbol)
{
var info = semanticModel.GetTypeInfo(token.Parent, cancellationToken);
symbol = info.Type;
}
// Just use syntaxfacts for operators
if (symbol is IMethodSymbol && ((IMethodSymbol)symbol).MethodKind == MethodKind.BuiltinOperator)
{
text = null;
return false;
}
text = symbol != null ? FormatSymbol(symbol) : null;
return symbol != null;
}