本文整理汇总了C#中SyntaxNode.IsKind方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.IsKind方法的具体用法?C# SyntaxNode.IsKind怎么用?C# SyntaxNode.IsKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxNode
的用法示例。
在下文中一共展示了SyntaxNode.IsKind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddAnchorIndentationOperations
public override void AddAnchorIndentationOperations(List<AnchorIndentationOperation> list, SyntaxNode node, OptionSet optionSet, NextAction<AnchorIndentationOperation> nextOperation)
{
if (node.IsKind(SyntaxKind.SimpleLambdaExpression) || node.IsKind(SyntaxKind.ParenthesizedLambdaExpression) || node.IsKind(SyntaxKind.AnonymousMethodExpression))
{
return;
}
nextOperation.Invoke(list);
}
示例2: IsCandidate
protected override bool IsCandidate(SyntaxNode node, Diagnostic diagnostic)
{
return node.IsKind(SyntaxKind.IdentifierName) ||
node.IsKind(SyntaxKind.MethodDeclaration) ||
node.IsKind(SyntaxKind.InvocationExpression) ||
node.IsKind(SyntaxKind.CastExpression) ||
node is LiteralExpressionSyntax ||
node is SimpleNameSyntax ||
node is ExpressionSyntax;
}
示例3: FieldOrPropertyInitializer
public FieldOrPropertyInitializer(FieldSymbol fieldOpt, SyntaxNode syntax, int precedingInitializersLength)
{
Debug.Assert(syntax.IsKind(SyntaxKind.EqualsValueClause) && fieldOpt != null || syntax is StatementSyntax);
FieldOpt = fieldOpt;
Syntax = syntax.GetReference();
PrecedingInitializersLength = precedingInitializersLength;
}
示例4: GetTargetNode
protected override SyntaxNode GetTargetNode(SyntaxNode node)
{
if (node.IsKind(SyntaxKind.MemberBindingExpression))
{
var nameNode = node.ChildNodes().FirstOrDefault(n => n.IsKind(SyntaxKind.IdentifierName));
if (nameNode != null)
{
return nameNode;
}
}
return base.GetTargetNode(node);
}
示例5: GetCodeFixAsync
protected override async Task<CodeAction> GetCodeFixAsync(SyntaxNode root, SyntaxNode node, Document document, Diagnostic diagnostics, CancellationToken cancellationToken)
{
// Check if node is return statement
if (!node.IsKind(SyntaxKind.ReturnStatement))
{
return null;
}
var returnStatement = node as ReturnStatementSyntax;
var model = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
ITypeSymbol methodReturnType;
if (!TryGetMethodReturnType(node, model, cancellationToken, out methodReturnType))
{
return null;
}
ITypeSymbol returnExpressionType;
if (!TryGetExpressionType(model, returnStatement.Expression, out returnExpressionType))
{
return null;
}
var typeArguments = methodReturnType.GetAllTypeArguments();
var shouldOfferYieldReturn = typeArguments.Length != 1 ?
IsCorrectTypeForYieldReturn(returnExpressionType, methodReturnType, model) :
IsCorrectTypeForYieldReturn(typeArguments.Single(), returnExpressionType, methodReturnType, model);
if (!shouldOfferYieldReturn)
{
return null;
}
var yieldStatement = SyntaxFactory.YieldStatement(
SyntaxKind.YieldReturnStatement,
returnStatement.Expression)
.WithAdditionalAnnotations(Formatter.Annotation);
root = root.ReplaceNode(returnStatement, yieldStatement);
return new MyCodeAction(CSharpFeaturesResources.ChangeToYieldReturn, document.WithSyntaxRoot(root));
}
示例6: IsNamedArgumentName
/// <summary>
/// Is the node the name of a named argument of an invocation, object creation expression,
/// constructor initializer, or element access, but not an attribute.
/// </summary>
public static bool IsNamedArgumentName(SyntaxNode node)
{
// An argument name is an IdentifierName inside a NameColon, inside an Argument, inside an ArgumentList, inside an
// Invocation, ObjectCreation, ObjectInitializer, or ElementAccess.
if (!node.IsKind(IdentifierName))
return false;
var parent1 = node.Parent;
if (parent1 == null || !parent1.IsKind(NameColon))
return false;
var parent2 = parent1.Parent;
if (parent2 == null || !(parent2.IsKind(Argument) || parent2.IsKind(AttributeArgument)))
return false;
var parent3 = parent2.Parent;
if (parent3 == null || !(parent3 is BaseArgumentListSyntax || parent3.IsKind(AttributeArgumentList)))
return false;
var parent4 = parent3.Parent;
if (parent4 == null)
return false;
switch (parent4.Kind())
{
case InvocationExpression:
case ObjectCreationExpression:
case ObjectInitializerExpression:
case ElementAccessExpression:
case Attribute:
case BaseConstructorInitializer:
case ThisConstructorInitializer:
return true;
default:
return false;
}
}
示例7: IsLocalDeclarationStatement
public bool IsLocalDeclarationStatement(SyntaxNode node)
{
return node.IsKind(SyntaxKind.LocalDeclarationStatement);
}
示例8: InferTypeForFirstParameterOfLambda
private ITypeSymbol InferTypeForFirstParameterOfLambda(
string parameterName,
SyntaxNode node)
{
if (node.IsKind(SyntaxKind.IdentifierName))
{
var identifierName = (IdentifierNameSyntax)node;
if (identifierName.Identifier.ValueText.Equals(parameterName) &&
SemanticModel.GetSymbolInfo(identifierName.Identifier).Symbol?.Kind == SymbolKind.Parameter)
{
return InferTypes(identifierName).FirstOrDefault().InferredType;
}
}
else
{
foreach (var child in node.ChildNodesAndTokens())
{
if (child.IsNode)
{
var type = InferTypeForFirstParameterOfLambda(parameterName, child.AsNode());
if (type != null)
{
return type;
}
}
}
}
return null;
}
示例9: IsMethodOrAnonymousFunction
protected override bool IsMethodOrAnonymousFunction(SyntaxNode node)
{
return node.IsKind(SyntaxKind.MethodDeclaration) || node.IsAnyLambdaOrAnonymousMethod();
}
示例10: IsNameOrMemberAccessButNoExpression
private static bool IsNameOrMemberAccessButNoExpression(SyntaxNode node)
{
if (node.IsKind(SyntaxKind.SimpleMemberAccessExpression))
{
var memberAccess = (MemberAccessExpressionSyntax)node;
return memberAccess.Expression.IsKind(SyntaxKind.IdentifierName) ||
IsNameOrMemberAccessButNoExpression(memberAccess.Expression);
}
return node.IsKind(SyntaxKind.IdentifierName);
}
示例11: IsInferredAnonymousObjectMemberDeclarator
public bool IsInferredAnonymousObjectMemberDeclarator(SyntaxNode node)
{
return node.IsKind(SyntaxKind.AnonymousObjectMemberDeclarator) &&
((AnonymousObjectMemberDeclaratorSyntax)node).NameEquals == null;
}
示例12: AddIndentBlockOperations
public override void AddIndentBlockOperations(List<IndentBlockOperation> list, SyntaxNode node, OptionSet optionSet, NextAction<IndentBlockOperation> nextOperation)
{
// these nodes should be from syntax tree from ITextSnapshot.
Contract.Requires(node.SyntaxTree != null);
Contract.Requires(node.SyntaxTree.GetText() != null);
nextOperation.Invoke(list);
ReplaceCaseIndentationRules(list, node);
if (node is BaseParameterListSyntax ||
node is TypeArgumentListSyntax ||
node is TypeParameterListSyntax ||
node.IsKind(SyntaxKind.Interpolation))
{
AddIndentBlockOperations(list, node);
return;
}
var argument = node as BaseArgumentListSyntax;
if (argument != null && argument.Parent.Kind() != SyntaxKind.ThisConstructorInitializer)
{
AddIndentBlockOperations(list, argument);
return;
}
// only valid if the user has started to actually type a constructor initializer
var constructorInitializer = node as ConstructorInitializerSyntax;
if (constructorInitializer != null &&
constructorInitializer.ArgumentList.OpenParenToken.Kind() != SyntaxKind.None &&
!constructorInitializer.ThisOrBaseKeyword.IsMissing)
{
var text = node.SyntaxTree.GetText();
// 3 different cases
// first case : this or base is the first token on line
// second case : colon is the first token on line
var colonIsFirstTokenOnLine = !constructorInitializer.ColonToken.IsMissing && constructorInitializer.ColonToken.IsFirstTokenOnLine(text);
var thisOrBaseIsFirstTokenOnLine = !constructorInitializer.ThisOrBaseKeyword.IsMissing && constructorInitializer.ThisOrBaseKeyword.IsFirstTokenOnLine(text);
if (colonIsFirstTokenOnLine || thisOrBaseIsFirstTokenOnLine)
{
list.Add(FormattingOperations.CreateRelativeIndentBlockOperation(
constructorInitializer.ThisOrBaseKeyword,
constructorInitializer.ArgumentList.OpenParenToken.GetNextToken(includeZeroWidth: true),
constructorInitializer.ArgumentList.CloseParenToken.GetPreviousToken(includeZeroWidth: true),
indentationDelta: 1,
option: IndentBlockOption.RelativePosition));
}
else
{
// third case : none of them are the first token on the line
AddIndentBlockOperations(list, constructorInitializer.ArgumentList);
}
}
}
示例13: TryGetEffectiveGetterBody
public static SyntaxNode TryGetEffectiveGetterBody(SyntaxNode declaration)
{
if (declaration.IsKind(SyntaxKind.PropertyDeclaration))
{
var property = (PropertyDeclarationSyntax)declaration;
return TryGetEffectiveGetterBody(property.ExpressionBody, property.AccessorList);
}
if (declaration.IsKind(SyntaxKind.IndexerDeclaration))
{
var indexer = (IndexerDeclarationSyntax)declaration;
return TryGetEffectiveGetterBody(indexer.ExpressionBody, indexer.AccessorList);
}
return null;
}
示例14: IsParameterlessConstructor
public static bool IsParameterlessConstructor(SyntaxNode declaration)
{
if (!declaration.IsKind(SyntaxKind.ConstructorDeclaration))
{
return false;
}
var ctor = (ConstructorDeclarationSyntax)declaration;
return ctor.ParameterList.Parameters.Count == 0;
}
示例15: IsIteratorMethod
public static bool IsIteratorMethod(SyntaxNode declaration)
{
// lambdas and expression-bodied methods can't be iterators:
if (!declaration.IsKind(SyntaxKind.MethodDeclaration))
{
return false;
}
// enumerate statements:
return declaration.DescendantNodes(n => !(n is ExpressionSyntax))
.Any(n => n.IsKind(SyntaxKind.YieldBreakStatement) || n.IsKind(SyntaxKind.YieldReturnStatement));
}