本文整理汇总了C#中AstNode.GetChildrenByRole方法的典型用法代码示例。如果您正苦于以下问题:C# AstNode.GetChildrenByRole方法的具体用法?C# AstNode.GetChildrenByRole怎么用?C# AstNode.GetChildrenByRole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AstNode
的用法示例。
在下文中一共展示了AstNode.GetChildrenByRole方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetModifiers
internal static Modifiers GetModifiers(AstNode node)
{
Modifiers m = 0;
foreach (CSharpModifierToken t in node.GetChildrenByRole (ModifierRole)) {
m |= t.Modifier;
}
return m;
}
示例2: SetModifiers
internal static void SetModifiers(AstNode node, Modifiers newValue)
{
Modifiers oldValue = GetModifiers(node);
AstNode insertionPos = node.GetChildrenByRole(AttributeRole).LastOrDefault();
foreach (Modifiers m in CSharpModifierToken.AllModifiers) {
if ((m & newValue) != 0) {
if ((m & oldValue) == 0) {
// Modifier was added
node.InsertChildAfter(insertionPos, new CSharpModifierToken(AstLocation.Empty, m), ModifierRole);
} else {
// Modifier already exists
insertionPos = node.GetChildrenByRole(ModifierRole).First(t => t.Modifier == m);
}
} else {
if ((m & oldValue) != 0) {
// Modifier was removed
node.GetChildrenByRole (ModifierRole).First(t => t.Modifier == m).Remove();
}
}
}
}
示例3: GetParameters
static int GetParameters (AstNode x)
{
return x.GetChildrenByRole (Roles.Parameter).Count ();
}
示例4: ReplaceWithFullTypeNameAction
CodeAction ReplaceWithFullTypeNameAction(RefactoringContext context, AstNode node, ITypeDefinition typeDefinition)
{
AstType astType = context.CreateShortType(typeDefinition);
string textWithoutGenerics = astType.ToString();
foreach (var typeArg in node.GetChildrenByRole(Roles.TypeArgument)) {
astType.AddChild(typeArg.Clone(), Roles.TypeArgument);
}
return new CodeAction(textWithoutGenerics, s => s.Replace(node, astType), node);
}
示例5: GetIdentifierName
private static string GetIdentifierName(AstNode node)
{
foreach (var obj in
from child in node.GetChildrenByRole(Roles.Identifier)
from propertyInfo in child
.GetType()
.GetProperties(
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.Public)
.Where(x => x.Name == "Name")
select propertyInfo.GetValue(child, null))
{
return obj.ToString();
}
throw new MissingFieldException("Missing Role 'Identifier' from AstNode");
}