本文整理汇总了C#中SyntaxToken.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxToken.GetType方法的具体用法?C# SyntaxToken.GetType怎么用?C# SyntaxToken.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxToken
的用法示例。
在下文中一共展示了SyntaxToken.GetType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddToken
private void AddToken(TreeViewItem parentItem, SyntaxToken token)
{
var kind = token.GetKind();
var tag = new SyntaxTag()
{
SyntaxToken = token,
Category = SyntaxCategory.SyntaxToken,
Span = token.Span,
FullSpan = token.FullSpan,
Kind = kind,
ParentItem = parentItem
};
var item = new TreeViewItem()
{
Tag = tag,
IsExpanded = false,
Foreground = Brushes.DarkGreen,
Background = token.ContainsDiagnostics ? Brushes.Pink : Brushes.White,
Header = tag.Kind + " " + token.Span.ToString()
};
if (SyntaxTree != null && token.ContainsDiagnostics)
{
item.ToolTip = string.Empty;
foreach (var diagnostic in SyntaxTree.GetDiagnostics(token))
{
item.ToolTip += diagnostic.ToString() + "\n";
}
item.ToolTip = item.ToolTip.ToString().Trim();
}
item.Selected += new RoutedEventHandler((sender, e) =>
{
_isNavigatingFromTreeToSource = true;
typeTextLabel.Visibility = Visibility.Visible;
kindTextLabel.Visibility = Visibility.Visible;
typeValueLabel.Content = token.GetType().Name;
kindValueLabel.Content = kind;
_propertyGrid.SelectedObject = token;
item.IsExpanded = true;
if (!_isNavigatingFromSourceToTree && SyntaxTokenNavigationToSourceRequested != null)
{
SyntaxTokenNavigationToSourceRequested(token);
}
_isNavigatingFromTreeToSource = false;
e.Handled = true;
});
item.Expanded += new RoutedEventHandler((sender, e) =>
{
if (item.Items.Count == 1 && item.Items[0] == null)
{
// Remove placeholder child and populate real children.
item.Items.RemoveAt(0);
foreach (var trivia in token.LeadingTrivia)
{
AddTrivia(item, trivia, true);
}
foreach (var trivia in token.TrailingTrivia)
{
AddTrivia(item, trivia, false);
}
}
});
if (parentItem == null)
{
treeView.Items.Clear();
treeView.Items.Add(item);
}
else
{
parentItem.Items.Add(item);
}
if (token.HasLeadingTrivia || token.HasTrailingTrivia)
{
if (IsLazy)
{
// Add placeholder child to indicate that real children need to be populated on expansion.
item.Items.Add(null);
}
else
{
// Recursively populate all descendants.
foreach (var trivia in token.LeadingTrivia)
{
AddTrivia(item, trivia, true);
}
foreach (var trivia in token.TrailingTrivia)
{
AddTrivia(item, trivia, false);
//.........这里部分代码省略.........
示例2: VisitToken
// Visits all SyntaxTokens.
public override void VisitToken(SyntaxToken token)
{
// We only care about SyntaxTokens with Kind 'IfKeyword'.
if (token.Kind() == SyntaxKind.IfKeyword)
{
Results.AppendLine();
Results.Append("Visiting ");
Results.Append(token.GetType().Name);
Results.Append(" (Kind = ");
Results.Append(token.Kind().ToString());
Results.Append("): ");
Results.Append(token.Parent.ToString());
}
base.VisitToken(token);
}