本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery.CSharpSyntaxContext类的典型用法代码示例。如果您正苦于以下问题:C# CSharpSyntaxContext类的具体用法?C# CSharpSyntaxContext怎么用?C# CSharpSyntaxContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CSharpSyntaxContext类属于Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery命名空间,在下文中一共展示了CSharpSyntaxContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsExtensionMethodParameterContext
private static bool IsExtensionMethodParameterContext(CSharpSyntaxContext context, CancellationToken cancellationToken)
{
// TODO(cyrusn): lambda/anon methods can have out/ref parameters
if (!context.SyntaxTree.IsParameterModifierContext(context.Position, context.LeftToken, cancellationToken, allowableIndex: 0))
{
return false;
}
var token = context.LeftToken;
var method = token.GetAncestor<MethodDeclarationSyntax>();
var typeDecl = method.GetAncestorOrThis<TypeDeclarationSyntax>();
if (method == null || typeDecl == null)
{
return false;
}
if (typeDecl.Kind() != SyntaxKind.ClassDeclaration)
{
return false;
}
if (!method.Modifiers.Any(t => t.Kind() == SyntaxKind.StaticKeyword))
{
return false;
}
if (!typeDecl.Modifiers.Any(t => t.Kind() == SyntaxKind.StaticKeyword))
{
return false;
}
return true;
}
示例2: IsValidContext
protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
{
var syntaxTree = context.SyntaxTree;
return
context.IsNonAttributeExpressionContext ||
context.IsDefiniteCastTypeContext ||
context.IsStatementContext ||
context.IsGlobalStatementContext ||
context.IsObjectCreationTypeContext ||
context.IsGenericTypeArgumentContext ||
context.IsEnumBaseListContext ||
context.IsIsOrAsTypeContext ||
context.IsLocalVariableDeclarationContext ||
context.IsFixedVariableDeclarationContext ||
context.IsParameterTypeContext ||
context.IsPossibleLambdaOrAnonymousMethodParameterTypeContext ||
context.IsImplicitOrExplicitOperatorTypeContext ||
context.IsPrimaryFunctionExpressionContext ||
context.IsCrefContext ||
syntaxTree.IsAfterKeyword(position, SyntaxKind.ConstKeyword, cancellationToken) ||
syntaxTree.IsAfterKeyword(position, SyntaxKind.StackAllocKeyword, cancellationToken) ||
context.IsDelegateReturnTypeContext ||
syntaxTree.IsGlobalMemberDeclarationContext(position, SyntaxKindSet.AllGlobalMemberModifiers, cancellationToken) ||
context.IsMemberDeclarationContext(
validModifiers: SyntaxKindSet.AllMemberModifiers,
validTypeDeclarations: SyntaxKindSet.ClassInterfaceStructTypeDeclarations,
canBePartial: false,
cancellationToken: cancellationToken);
}
示例3: IsValidContext
protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
{
return
context.IsStatementContext ||
context.IsGlobalStatementContext ||
context.IsNonAttributeExpressionContext;
}
示例4: IsValidContext
protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
{
return
IsInstanceExpressionOrStatement(context) ||
IsExtensionMethodParameterContext(context, cancellationToken) ||
IsConstructorInitializerContext(context);
}
示例5: IsValidContext
protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
{
return
context.IsGlobalStatementContext ||
IsMemberDeclarationContext(context, cancellationToken) ||
IsTypeDeclarationContext(context, cancellationToken);
}
示例6: GetSymbolsForCurrentContext
private static IEnumerable<ISymbol> GetSymbolsForCurrentContext(
CSharpSyntaxContext context,
bool filterOutOfScopeLocals,
CancellationToken cancellationToken)
{
if (context.IsGlobalStatementContext)
{
// Script and interactive
return GetSymbolsForGlobalStatementContext(context, cancellationToken);
}
else if (context.IsAnyExpressionContext || context.IsStatementContext)
{
return GetSymbolsForExpressionOrStatementContext(context, filterOutOfScopeLocals, cancellationToken);
}
else if (context.IsTypeContext || context.IsNamespaceContext)
{
return GetSymbolsForTypeOrNamespaceContext(context, cancellationToken);
}
else if (context.IsLabelContext)
{
return GetSymbolsForLabelContext(context, cancellationToken);
}
else if (context.IsTypeArgumentOfConstraintContext)
{
return GetSymbolsForTypeArgumentOfConstraintClause(context, cancellationToken);
}
else if (context.IsDestructorTypeContext)
{
return SpecializedCollections.SingletonEnumerable(context.SemanticModel.GetDeclaredSymbol(context.ContainingTypeOrEnumDeclaration, cancellationToken));
}
return SpecializedCollections.EmptyEnumerable<ISymbol>();
}
示例7: IsValidContext
protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
{
if (context.IsAnyExpressionContext || context.IsStatementContext)
{
foreach (var node in context.LeftToken.GetAncestors<SyntaxNode>())
{
if (node.IsAnyLambdaOrAnonymousMethod())
{
return true;
}
if (node.IsKind(SyntaxKind.QueryExpression))
{
return false;
}
if (node.IsKind(SyntaxKind.LockStatement))
{
var lockStatement = (LockStatementSyntax)node;
if (lockStatement.Statement != null &&
!lockStatement.Statement.IsMissing &&
lockStatement.Statement.Span.Contains(position))
{
return false;
}
}
}
return true;
}
return false;
}
示例8: IsValidContext
protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
{
if (context.IsStatementContext ||
context.IsGlobalStatementContext)
{
return true;
}
// do {
// } |
// do {
// } w|
// Note: the case of
// do
// Foo();
// |
// is taken care of in the IsStatementContext case.
var token = context.TargetToken;
if (token.Kind() == SyntaxKind.CloseBraceToken &&
token.Parent.IsKind(SyntaxKind.Block) &&
token.Parent.IsParentKind(SyntaxKind.DoStatement))
{
return true;
}
return false;
}
示例9: IsValidContext
protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
{
// cases:
// join a in expr o1 |
// join a in expr o1 e|
var token = context.TargetToken;
var join = token.GetAncestor<JoinClauseSyntax>();
if (join == null)
{
return false;
}
var lastToken = join.LeftExpression.GetLastToken(includeSkipped: true);
// join a in expr |
if (join.LeftExpression.Width() > 0 &&
token == lastToken)
{
return true;
}
return false;
}
示例10: IsValidContext
protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
{
return
IsValidContextForAccessor(context) ||
IsValidContextForType(context, cancellationToken) ||
IsValidContextForMember(context, cancellationToken);
}
示例11: IsValidContextInForEachClause
private bool IsValidContextInForEachClause(CSharpSyntaxContext context)
{
// cases:
// foreach (var v |
// foreach (var v i|
// foreach (var (x, y) |
var token = context.TargetToken;
if (token.Kind() == SyntaxKind.IdentifierToken)
{
var statement = token.Parent as ForEachStatementSyntax;
if (statement != null && token == statement.Identifier)
{
return true;
}
}
else if (token.Kind() == SyntaxKind.CloseParenToken)
{
var statement = token.GetAncestor<ForEachComponentStatementSyntax>();
if (statement != null && token.Span.End == statement.VariableComponent.Span.End)
{
return true;
}
}
return false;
}
示例12: IsValidContext
protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
{
return
context.IsStatementContext ||
context.TargetToken.IsAfterYieldKeyword() ||
IsAttributeContext(context, cancellationToken);
}
示例13: IsMemberDeclarationContext
private static bool IsMemberDeclarationContext(CSharpSyntaxContext context, CancellationToken cancellationToken)
{
return
context.TargetToken.IsUnsafeContext() &&
(context.SyntaxTree.IsGlobalMemberDeclarationContext(context.Position, SyntaxKindSet.AllGlobalMemberModifiers, cancellationToken) ||
context.IsMemberDeclarationContext(validModifiers: s_validModifiers, validTypeDeclarations: SyntaxKindSet.StructOnlyTypeDeclarations, canBePartial: false, cancellationToken: cancellationToken));
}
示例14: IsInBreakableConstructContext
private static bool IsInBreakableConstructContext(CSharpSyntaxContext context)
{
if (!context.IsStatementContext)
{
return false;
}
// allowed if we're inside a loop/switch construct.
var token = context.LeftToken;
foreach (var v in token.GetAncestors<SyntaxNode>())
{
if (v.IsAnyLambdaOrAnonymousMethod())
{
// if we hit a lambda while walking up, then we can't
// 'continue' any outer loops.
return false;
}
if (v.IsBreakableConstruct())
{
return true;
}
}
return false;
}
示例15: IsValidContext
protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
{
// cases:
// group e |
// group e b|
var token = context.LeftToken;
var group = token.GetAncestor<GroupClauseSyntax>();
if (group == null)
{
return false;
}
var lastToken = group.GroupExpression.GetLastToken(includeSkipped: true);
// group e |
if (!token.IntersectsWith(position) &&
token == lastToken)
{
return true;
}
// group e b|
if (token.IntersectsWith(position) &&
token.Kind() == SyntaxKind.IdentifierToken &&
token.GetPreviousToken(includeSkipped: true) == lastToken)
{
return true;
}
return false;
}