本文整理汇总了C#中Microsoft.CodeAnalysis.SyntaxNode.ChildTokens方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.ChildTokens方法的具体用法?C# SyntaxNode.ChildTokens怎么用?C# SyntaxNode.ChildTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.SyntaxNode
的用法示例。
在下文中一共展示了SyntaxNode.ChildTokens方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsSingleCharViolation
private bool IsSingleCharViolation(SyntaxNode declaration)
{
var identifier = declaration.ChildTokens().First(t => t.RawKind == IdentifierToken);
if (IsInLoop(declaration)) return false;
if (IsInLamda(declaration)) return false;
return identifier.Value.ToString().Length == 1;
}
示例2: GetDiagnosticLocation
private static Location GetDiagnosticLocation(SyntaxNode node)
{
if (node.HasLeadingTrivia)
{
return node.GetLeadingTrivia()[0].GetLocation();
}
var firstToken = node.ChildTokens().FirstOrDefault();
if (firstToken != default(SyntaxToken))
{
return node.ChildTokens().First().GetLocation();
}
return Location.None;
}
示例3: DetermineContentPosition
/// <summary>
/// Determines the content's block position depending on the node type.
/// </summary>
/// <param name="node">The node to extract the content position from.</param>
/// <returns>The determined content position or 0 if not found.</returns>
private int DetermineContentPosition(SyntaxNode node)
{
if(node == null)
{
throw new ArgumentNullException(nameof(node));
}
// Select the content node element depending on the node type
TextSpan? contentTextSpan = null;
switch (node.Kind())
{
// Accessor list content
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.IndexerDeclaration:
case SyntaxKind.EventDeclaration:
AccessorListSyntax accessorList = node.DescendantNodes().OfType<AccessorListSyntax>().FirstOrDefault();
if (null != accessorList)
{
contentTextSpan = accessorList.FullSpan;
}
break;
// Contains children
case SyntaxKind.NamespaceDeclaration:
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.ClassDeclaration:
SyntaxToken token = node.ChildTokens().FirstOrDefault(x => x.Kind() == SyntaxKind.OpenBraceToken);
if (null != token)
{
contentTextSpan = token.FullSpan;
}
break;
// Block content
case SyntaxKind.ConstructorDeclaration:
case SyntaxKind.DestructorDeclaration:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.GetAccessorDeclaration:
case SyntaxKind.SetAccessorDeclaration:
case SyntaxKind.AddAccessorDeclaration:
case SyntaxKind.RemoveAccessorDeclaration:
BlockSyntax block = node.DescendantNodes().OfType<BlockSyntax>().FirstOrDefault();
if (null != block)
{
contentTextSpan = block.FullSpan;
}
break;
// Not processed by projbook csharp extractor
default:
break;
}
// Compute a line break insensitive position based on the fetched content text span if any is found
if (null != contentTextSpan)
{
int relativeTextSpanStart = contentTextSpan.Value.Start - node.FullSpan.Start;
return node
.ToFullString()
.Substring(0, relativeTextSpanStart)
.Replace("\r\n", "")
.Replace("\n", "").Length;
}
// Otherwise return 0 as default value
return 0;
}
示例4: IsNumberSeriesViolation
// TODO: Exception e is allowed
private bool IsNumberSeriesViolation(SyntaxNode declaration)
{
const string numberSeriesRegex = "^[a-zA-Z][0-9]{1,3}$";
var identifier = declaration.ChildTokens().First(t => t.RawKind == IdentifierToken);
return Regex.IsMatch(identifier.Value.ToString(), numberSeriesRegex);
}