本文整理汇总了C#中CSharpSyntaxNode.IsKind方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpSyntaxNode.IsKind方法的具体用法?C# CSharpSyntaxNode.IsKind怎么用?C# CSharpSyntaxNode.IsKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSharpSyntaxNode
的用法示例。
在下文中一共展示了CSharpSyntaxNode.IsKind方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateSpeculative
/// <summary>
/// Creates a speculative SemanticModel for an initializer node (field initializer, constructor initializer, or parameter default value)
/// that did not appear in the original source code.
/// </summary>
internal static InitializerSemanticModel CreateSpeculative(SyntaxTreeSemanticModel parentSemanticModel, Symbol owner, CSharpSyntaxNode syntax, Binder rootBinder, int position)
{
Debug.Assert(parentSemanticModel != null);
Debug.Assert(syntax != null);
Debug.Assert(syntax.IsKind(SyntaxKind.EqualsValueClause) || syntax.IsKind(SyntaxKind.ThisConstructorInitializer) || syntax.IsKind(SyntaxKind.BaseConstructorInitializer));
Debug.Assert(rootBinder != null);
Debug.Assert(rootBinder.IsSemanticModelBinder);
return new InitializerSemanticModel(parentSemanticModel.Compilation, syntax, owner, rootBinder, parentSemanticModel, position);
}
示例2: AppendImplicitReturn
// insert the implicit "return" statement at the end of the method body
// Normally, we wouldn't bother attaching syntax trees to compiler-generated nodes, but these
// ones are going to have sequence points.
internal static BoundBlock AppendImplicitReturn(BoundBlock body, MethodSymbol method, CSharpSyntaxNode syntax = null)
{
Debug.Assert(body != null);
Debug.Assert(method != null);
if (syntax == null)
{
syntax = body.Syntax;
}
Debug.Assert(body.WasCompilerGenerated || syntax.IsKind(SyntaxKind.Block) || syntax.IsKind(SyntaxKind.ArrowExpressionClause));
BoundStatement ret = method.IsIterator
? (BoundStatement)BoundYieldBreakStatement.Synthesized(syntax)
: BoundReturnStatement.Synthesized(syntax, null);
// Implicitly added return for async method does not need sequence points since lowering would add one.
if (syntax.IsKind(SyntaxKind.Block) && !method.IsAsync)
{
var blockSyntax = (BlockSyntax)syntax;
ret = new BoundSequencePointWithSpan(
blockSyntax,
ret,
blockSyntax.CloseBraceToken.Span)
{ WasCompilerGenerated = true };
}
switch (body.Kind)
{
case BoundKind.Block:
return body.Update(body.Locals, body.Statements.Add(ret));
default:
return new BoundBlock(syntax, ImmutableArray<LocalSymbol>.Empty, ImmutableArray.Create(ret, body));
}
}
示例3: Create
/// <summary>
/// Creates a SemanticModel for an autoprop initializer of a named type
/// </summary>
internal static InitializerSemanticModel Create(CSharpCompilation compilation, CSharpSyntaxNode syntax, PropertySymbol propertySymbol, Binder rootBinder)
{
Debug.Assert(syntax.IsKind(SyntaxKind.PropertyDeclaration));
return new InitializerSemanticModel(compilation, syntax, propertySymbol, rootBinder);
}
示例4: AppendImplicitReturn
// insert the implicit "return" statement at the end of the method body
// Normally, we wouldn't bother attaching syntax trees to compiler-generated nodes, but these
// ones are going to have sequence points.
internal static BoundBlock AppendImplicitReturn(BoundBlock body, MethodSymbol method, CSharpSyntaxNode syntax = null)
{
Debug.Assert(body != null);
Debug.Assert(method != null);
if (syntax == null)
{
syntax = body.Syntax;
}
Debug.Assert(body.WasCompilerGenerated || syntax.IsKind(SyntaxKind.Block) || syntax.IsKind(SyntaxKind.ArrowExpressionClause));
BoundStatement ret = method.IsIterator
? (BoundStatement)BoundYieldBreakStatement.Synthesized(syntax)
: BoundReturnStatement.Synthesized(syntax, RefKind.None, null);
return body.Update(body.Locals, body.LocalFunctions, body.Statements.Add(ret));
}
示例5: IsValidForHoisting
private static bool IsValidForHoisting(ParameterSyntax parameter, CSharpSyntaxNode node)
{
if (node.IsKind(SyntaxKind.IdentifierName))
{
var identifier = (IdentifierNameSyntax)node;
if (identifier.Identifier.Text == parameter.Identifier.Text)
{
return true;
}
}
else if (node.IsKind(SyntaxKind.SimpleMemberAccessExpression))
{
var memberAccess = (MemberAccessExpressionSyntax)node;
var lhs = memberAccess.Expression;
return IsValidForHoisting(parameter, lhs);
}
return false;
}
示例6: AssertIsLambdaScopeSyntax
private static void AssertIsLambdaScopeSyntax(CSharpSyntaxNode syntaxOpt)
{
// See C# specification, chapter 3.7 Scopes.
// static lambdas technically have the class scope so the scope syntax is null
if (syntaxOpt == null)
{
return;
}
// block:
if (syntaxOpt.IsKind(SyntaxKind.Block))
{
return;
}
// switch block:
if (syntaxOpt.IsKind(SyntaxKind.SwitchStatement))
{
return;
}
// expression-bodied member:
if (syntaxOpt.IsKind(SyntaxKind.ArrowExpressionClause))
{
return;
}
// catch clause (including filter):
if (syntaxOpt.IsKind(SyntaxKind.CatchClause))
{
return;
}
// class/struct containing a field/property with a declaration expression
if (syntaxOpt.IsKind(SyntaxKind.ClassDeclaration) || syntaxOpt.IsKind(SyntaxKind.StructDeclaration))
{
return;
}
// lambda in a let clause,
// e.g. from item in array let a = new Func<int>(() => item)
if (syntaxOpt.IsKind(SyntaxKind.LetClause))
{
return;
}
if (IsStatementWithEmbeddedStatementBody(syntaxOpt.Kind()))
{
return;
}
// lambda bodies:
if (SyntaxFacts.IsLambdaBody(syntaxOpt))
{
return;
}
// lambda in a ctor initializer that refers to a ctor parameter
if (syntaxOpt.IsKind(SyntaxKind.ConstructorDeclaration))
{
return;
}
// TODO: EE expression
if (syntaxOpt is ExpressionSyntax && syntaxOpt.Parent.Parent == null)
{
return;
}
throw ExceptionUtilities.UnexpectedValue(syntaxOpt.Kind());
}