本文整理汇总了C#中SymbolInfo.GetBestOrAllSymbols方法的典型用法代码示例。如果您正苦于以下问题:C# SymbolInfo.GetBestOrAllSymbols方法的具体用法?C# SymbolInfo.GetBestOrAllSymbols怎么用?C# SymbolInfo.GetBestOrAllSymbols使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymbolInfo
的用法示例。
在下文中一共展示了SymbolInfo.GetBestOrAllSymbols方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSymbolsOffOfBoundExpression
private static ImmutableArray<ISymbol> GetSymbolsOffOfBoundExpression(
CSharpSyntaxContext context,
ExpressionSyntax originalExpression,
ExpressionSyntax expression,
SymbolInfo leftHandBinding,
INamespaceOrTypeSymbol container,
CancellationToken cancellationToken)
{
var useBaseReferenceAccessibility = false;
var excludeInstance = false;
var excludeStatic = false;
var symbol = leftHandBinding.GetBestOrAllSymbols().FirstOrDefault();
if (symbol != null)
{
// If the thing on the left is a type, namespace or alias and the original
// expression was parenthesized, we shouldn't show anything in IntelliSense.
if (originalExpression.IsKind(SyntaxKind.ParenthesizedExpression) &&
symbol.MatchesKind(SymbolKind.NamedType,
SymbolKind.Namespace,
SymbolKind.Alias))
{
return ImmutableArray<ISymbol>.Empty;
}
// If the thing on the left is a lambda expression, we shouldn't show anything.
if (symbol.Kind == SymbolKind.Method &&
((IMethodSymbol)symbol).MethodKind == MethodKind.AnonymousFunction)
{
return ImmutableArray<ISymbol>.Empty;
}
// If the thing on the left is an event that can't be used as a field, we shouldn't show anything
if (symbol.Kind == SymbolKind.Event &&
!context.SemanticModel.IsEventUsableAsField(originalExpression.SpanStart, (IEventSymbol)symbol))
{
return ImmutableArray<ISymbol>.Empty;
}
// If the thing on the left is a this parameter (e.g. this or base) and we're in a static context,
// we shouldn't show anything
if (symbol.IsThisParameter() &&
expression.IsInStaticContext())
{
return ImmutableArray<ISymbol>.Empty;
}
// What is the thing on the left?
switch (symbol.Kind)
{
case SymbolKind.NamedType:
case SymbolKind.Namespace:
excludeInstance = true;
container = (INamespaceOrTypeSymbol)symbol;
break;
case SymbolKind.Alias:
excludeInstance = true;
container = ((IAliasSymbol)symbol).Target;
break;
case SymbolKind.Parameter:
var parameter = (IParameterSymbol)symbol;
excludeStatic = true;
// case:
// base.|
if (parameter.IsThis && !object.Equals(parameter.Type, container))
{
useBaseReferenceAccessibility = true;
}
break;
default:
excludeStatic = true;
break;
}
}
else if (container != null)
{
excludeStatic = true;
}
else
{
return ImmutableArray<ISymbol>.Empty;
}
Debug.Assert(!excludeInstance || !excludeStatic);
Debug.Assert(!excludeInstance || !useBaseReferenceAccessibility);
// nameof(X.|
// Show static and instance members.
if (context.IsNameOfContext)
{
excludeInstance = false;
excludeStatic = false;
}
//.........这里部分代码省略.........