本文整理汇总了C#中CSharpSyntaxNode.Kind方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpSyntaxNode.Kind方法的具体用法?C# CSharpSyntaxNode.Kind怎么用?C# CSharpSyntaxNode.Kind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSharpSyntaxNode
的用法示例。
在下文中一共展示了CSharpSyntaxNode.Kind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Bind
internal override BoundNode Bind(Binder binder, CSharpSyntaxNode node, DiagnosticBag diagnostics)
{
if (node.Kind() == SyntaxKind.ArrowExpressionClause)
{
return binder.BindExpressionBodyAsBlock((ArrowExpressionClauseSyntax)node, diagnostics);
}
return base.Bind(binder, node, diagnostics);
}
示例2: MethodBodySemanticModel
private MethodBodySemanticModel(CSharpCompilation compilation, Symbol owner, Binder rootBinder, CSharpSyntaxNode syntax, SyntaxTreeSemanticModel parentSemanticModelOpt = null, int speculatedPosition = 0)
: base(compilation, syntax, owner, rootBinder, parentSemanticModelOpt, speculatedPosition)
{
Debug.Assert((object)owner != null);
Debug.Assert(owner.Kind == SymbolKind.Method);
Debug.Assert(syntax != null);
Debug.Assert(syntax.Kind() != SyntaxKind.CompilationUnit);
}
示例3: AddLocalDeclarationSequencePointIfNecessary
private BoundStatement AddLocalDeclarationSequencePointIfNecessary(CSharpSyntaxNode syntax, LocalSymbol localSymbol, BoundStatement rewrittenLocalDeclaration, bool wasCompilerGenerated = false)
{
// Add sequence points, if necessary.
if (this.GenerateDebugInfo && !wasCompilerGenerated && !localSymbol.IsConst && syntax.Kind() == SyntaxKind.VariableDeclarator)
{
Debug.Assert(syntax.SyntaxTree != null);
rewrittenLocalDeclaration = AddSequencePoint((VariableDeclaratorSyntax)syntax, rewrittenLocalDeclaration);
}
return rewrittenLocalDeclaration;
}
示例4: BuildMap
// methodsWithYields will contain all function-declaration-like CSharpSyntaxNodes with yield statements contained within them.
// Currently the types of these are restricted to only be whatever the syntax parameter is, plus any LocalFunctionStatementSyntax contained within it.
// This may change if the language is extended to allow iterator lambdas, in which case the lambda would also be returned.
// (lambdas currently throw a diagnostic in WithLambdaParametersBinder.GetIteratorElementType when a yield is used within them)
public static SmallDictionary<CSharpSyntaxNode, Binder> BuildMap(
Symbol containingMemberOrLambda,
CSharpSyntaxNode syntax,
Binder enclosing,
ArrayBuilder<CSharpSyntaxNode> methodsWithYields,
Func<Binder, CSharpSyntaxNode, Binder> rootBinderAdjusterOpt = null)
{
var builder = new LocalBinderFactory(containingMemberOrLambda, syntax, enclosing, methodsWithYields);
StatementSyntax statement;
if (syntax is ExpressionSyntax)
{
enclosing = new ExpressionVariableBinder(syntax, enclosing);
if ((object)rootBinderAdjusterOpt != null)
{
enclosing = rootBinderAdjusterOpt(enclosing, syntax);
}
builder.AddToMap(syntax, enclosing);
builder.Visit(syntax, enclosing);
}
else if (syntax.Kind() != SyntaxKind.Block && (statement = syntax as StatementSyntax) != null)
{
CSharpSyntaxNode embeddedScopeDesignator;
enclosing = builder.GetBinderForPossibleEmbeddedStatement(statement, enclosing, out embeddedScopeDesignator);
if ((object)rootBinderAdjusterOpt != null)
{
enclosing = rootBinderAdjusterOpt(enclosing, embeddedScopeDesignator);
}
if (embeddedScopeDesignator != null)
{
builder.AddToMap(embeddedScopeDesignator, enclosing);
}
builder.Visit(statement, enclosing);
}
else
{
if ((object)rootBinderAdjusterOpt != null)
{
enclosing = rootBinderAdjusterOpt(enclosing, null);
}
builder.Visit(syntax, enclosing);
}
// the other place this is possible is in a local function
if (builder._sawYield)
methodsWithYields.Add(syntax);
return builder._map;
}
示例5: FindExpressionVariables
internal static void FindExpressionVariables(
Binder scopeBinder,
ArrayBuilder<LocalSymbol> builder,
CSharpSyntaxNode node,
Binder enclosingBinderOpt = null)
{
if (node == null)
{
return;
}
var finder = s_poolInstance.Allocate();
finder._scopeBinder = scopeBinder;
finder._enclosingBinder = enclosingBinderOpt ?? scopeBinder;
finder._localsBuilder = builder;
#if DEBUG
// These are all of the kinds of nodes we should need to handle in this class.
// If you add to this list, make sure you handle that node kind with a visitor.
switch (node.Kind())
{
case SyntaxKind.EqualsValueClause:
case SyntaxKind.ArrowExpressionClause:
case SyntaxKind.SwitchSection:
case SyntaxKind.Attribute:
case SyntaxKind.ThrowStatement:
case SyntaxKind.ReturnStatement:
case SyntaxKind.YieldReturnStatement:
case SyntaxKind.ExpressionStatement:
case SyntaxKind.WhileStatement:
case SyntaxKind.DoStatement:
case SyntaxKind.LockStatement:
case SyntaxKind.IfStatement:
case SyntaxKind.SwitchStatement:
case SyntaxKind.VariableDeclarator:
break;
case SyntaxKind.ArgumentList:
Debug.Assert(node.Parent is ConstructorInitializerSyntax);
break;
default:
Debug.Assert(node is ExpressionSyntax);
break;
}
#endif
finder.VisitNodeToBind(node);
finder._scopeBinder = null;
finder._enclosingBinder = null;
finder._localsBuilder = null;
s_poolInstance.Free(finder);
}
示例6: ParsedSyntaxTree
internal ParsedSyntaxTree(SourceText textOpt, Encoding encodingOpt, SourceHashAlgorithm checksumAlgorithm, string path, CSharpParseOptions options, CSharpSyntaxNode root, Syntax.InternalSyntax.DirectiveStack directives, bool cloneRoot = true)
{
Debug.Assert(root != null);
Debug.Assert(options != null);
Debug.Assert(textOpt == null || textOpt.Encoding == encodingOpt && textOpt.ChecksumAlgorithm == checksumAlgorithm);
_lazyText = textOpt;
_encodingOpt = encodingOpt ?? textOpt?.Encoding;
_checksumAlgorithm = checksumAlgorithm;
_options = options;
_path = path ?? string.Empty;
_root = cloneRoot ? this.CloneNodeAsRoot(root) : root;
_hasCompilationUnitRoot = root.Kind() == SyntaxKind.CompilationUnit;
this.SetDirectiveStack(directives);
}
示例7: GetDeclaredLocalsForScope
internal override ImmutableArray<LocalSymbol> GetDeclaredLocalsForScope(CSharpSyntaxNode node)
{
if (node.Kind() == SyntaxKind.Block)
{
if (((BlockSyntax)node).Statements == _statements)
{
return this.Locals;
}
}
else if (_statements.Count == 1 && _statements.First() == node)
{
return this.Locals;
}
throw ExceptionUtilities.Unreachable;
}
示例8: Bind
internal override BoundNode Bind(Binder binder, CSharpSyntaxNode node, DiagnosticBag diagnostics)
{
if (node.Kind() == SyntaxKind.Attribute)
{
var attribute = (AttributeSyntax)node;
return binder.BindAttribute(attribute, AttributeType, diagnostics);
}
else if (SyntaxFacts.IsAttributeName(node))
{
return new BoundTypeExpression((NameSyntax)node, _aliasOpt, inferredType: false, type: AttributeType);
}
else
{
return base.Bind(binder, node, diagnostics);
}
}
示例9: AssertIsClosureScopeSyntax
private static void AssertIsClosureScopeSyntax(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;
}
if (LambdaUtilities.IsClosureScope(syntaxOpt))
{
return;
}
throw ExceptionUtilities.UnexpectedValue(syntaxOpt.Kind());
}
示例10: IsMatchingScopeDesignator
private bool IsMatchingScopeDesignator(CSharpSyntaxNode scopeDesignator)
{
if (scopeDesignator.Kind() == SyntaxKind.Block)
{
if (((BlockSyntax)scopeDesignator).Statements == _statements)
{
return true;
}
}
else if (_statements.Count == 1 && _statements.First() == scopeDesignator)
{
// This code compensates for the fact that we fake an enclosing block
// when there is an (illegal) local declaration as a controlled statement.
return true;
}
return false;
}
示例11: GetLastIdentifierValueText
private static string GetLastIdentifierValueText(CSharpSyntaxNode node)
{
var result = string.Empty;
switch (node.Kind())
{
case SyntaxKind.IdentifierName:
result = ((IdentifierNameSyntax)node).Identifier.ValueText;
break;
case SyntaxKind.QualifiedName:
result = GetLastIdentifierValueText(((QualifiedNameSyntax)node).Right);
break;
case SyntaxKind.GenericName:
var genericNameSyntax = ((GenericNameSyntax)node);
result = $"{genericNameSyntax.Identifier.ValueText}{genericNameSyntax.TypeArgumentList.ToString()}";
break;
case SyntaxKind.AliasQualifiedName:
result = ((AliasQualifiedNameSyntax)node).Name.Identifier.ValueText;
break;
}
return result;
}
示例12: 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(BoundStatement node, MethodSymbol method, CSharpSyntaxNode syntax = null)
{
Debug.Assert(method != null);
if (syntax == null)
{
syntax = node.Syntax;
}
BoundStatement ret = method.IsIterator
? (BoundStatement)BoundYieldBreakStatement.Synthesized(syntax)
: BoundReturnStatement.Synthesized(syntax, null);
if (syntax.Kind() == SyntaxKind.Block)
{
// Implicitly added return for async method does not need sequence points since lowering would add one.
if (!method.IsAsync)
{
var blockSyntax = (BlockSyntax)syntax;
ret = new BoundSequencePointWithSpan(
blockSyntax,
ret,
blockSyntax.CloseBraceToken.Span)
{ WasCompilerGenerated = true };
}
}
switch (node.Kind)
{
case BoundKind.Block:
var block = (BoundBlock)node;
return block.Update(block.Locals, block.Statements.Add(ret));
default:
return new BoundBlock(syntax, ImmutableArray<LocalSymbol>.Empty, ImmutableArray.Create(ret, node));
}
}
示例13: GetBindableSyntaxNode
internal protected override CSharpSyntaxNode GetBindableSyntaxNode(CSharpSyntaxNode node)
{
switch (node.Kind())
{
case SyntaxKind.Attribute:
return node;
case SyntaxKind.AttributeArgument:
// Try to walk up to the AttributeSyntax
var parent = node.Parent;
if (parent != null)
{
parent = parent.Parent;
if (parent != null)
{
return parent;
}
}
break;
}
return base.GetBindableSyntaxNode(node);
}
示例14: GetDeclaredTypeMemberContainer
private NamespaceOrTypeSymbol GetDeclaredTypeMemberContainer(CSharpSyntaxNode memberDeclaration)
{
if (memberDeclaration.Parent.Kind() == SyntaxKind.CompilationUnit)
{
// top-level namespace:
if (memberDeclaration.Kind() == SyntaxKind.NamespaceDeclaration)
{
return _compilation.Assembly.GlobalNamespace;
}
// top-level members in script or interactive code:
if (this.SyntaxTree.Options.Kind != SourceCodeKind.Regular)
{
return this.Compilation.ScriptClass;
}
// top-level type in an explicitly declared namespace:
if (SyntaxFacts.IsTypeDeclaration(memberDeclaration.Kind()))
{
return _compilation.Assembly.GlobalNamespace;
}
// other top-level members:
return _compilation.Assembly.GlobalNamespace.ImplicitType;
}
var container = GetDeclaredNamespaceOrType(memberDeclaration.Parent);
Debug.Assert((object)container != null);
// member in a type:
if (!container.IsNamespace)
{
return container;
}
// a namespace or a type in an explicitly declared namespace:
if (memberDeclaration.Kind() == SyntaxKind.NamespaceDeclaration || SyntaxFacts.IsTypeDeclaration(memberDeclaration.Kind()))
{
return container;
}
// another member in a namespace:
return ((NamespaceSymbol)container).ImplicitType;
}
示例15: GetDeclarationName
private string GetDeclarationName(CSharpSyntaxNode declaration)
{
switch (declaration.Kind())
{
case SyntaxKind.MethodDeclaration:
{
var methodDecl = (MethodDeclarationSyntax)declaration;
return GetDeclarationName(declaration, methodDecl.ExplicitInterfaceSpecifier, methodDecl.Identifier.ValueText);
}
case SyntaxKind.PropertyDeclaration:
{
var propertyDecl = (PropertyDeclarationSyntax)declaration;
return GetDeclarationName(declaration, propertyDecl.ExplicitInterfaceSpecifier, propertyDecl.Identifier.ValueText);
}
case SyntaxKind.IndexerDeclaration:
{
var indexerDecl = (IndexerDeclarationSyntax)declaration;
return GetDeclarationName(declaration, indexerDecl.ExplicitInterfaceSpecifier, WellKnownMemberNames.Indexer);
}
case SyntaxKind.EventDeclaration:
{
var eventDecl = (EventDeclarationSyntax)declaration;
return GetDeclarationName(declaration, eventDecl.ExplicitInterfaceSpecifier, eventDecl.Identifier.ValueText);
}
case SyntaxKind.DelegateDeclaration:
return ((DelegateDeclarationSyntax)declaration).Identifier.ValueText;
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.StructDeclaration:
case SyntaxKind.ClassDeclaration:
case SyntaxKind.EnumDeclaration:
return ((BaseTypeDeclarationSyntax)declaration).Identifier.ValueText;
case SyntaxKind.VariableDeclarator:
return ((VariableDeclaratorSyntax)declaration).Identifier.ValueText;
case SyntaxKind.EnumMemberDeclaration:
return ((EnumMemberDeclarationSyntax)declaration).Identifier.ValueText;
case SyntaxKind.DestructorDeclaration:
return WellKnownMemberNames.DestructorName;
case SyntaxKind.ConstructorDeclaration:
if (((ConstructorDeclarationSyntax)declaration).Modifiers.Any(SyntaxKind.StaticKeyword))
{
return WellKnownMemberNames.StaticConstructorName;
}
else
{
return WellKnownMemberNames.InstanceConstructorName;
}
case SyntaxKind.OperatorDeclaration:
var operatorDecl = (OperatorDeclarationSyntax)declaration;
return OperatorFacts.OperatorNameFromDeclaration(operatorDecl);
case SyntaxKind.ConversionOperatorDeclaration:
if (((ConversionOperatorDeclarationSyntax)declaration).ImplicitOrExplicitKeyword.Kind() == SyntaxKind.ExplicitKeyword)
{
return WellKnownMemberNames.ExplicitConversionName;
}
else
{
return WellKnownMemberNames.ImplicitConversionName;
}
case SyntaxKind.EventFieldDeclaration:
case SyntaxKind.FieldDeclaration:
throw new ArgumentException(CSharpResources.InvalidGetDeclarationNameMultipleDeclarators);
case SyntaxKind.IncompleteMember:
// There is no name - that's why it's an incomplete member.
return null;
default:
throw ExceptionUtilities.UnexpectedValue(declaration.Kind());
}
}