本文整理汇总了C#中AstNode.InsertChildAfter方法的典型用法代码示例。如果您正苦于以下问题:C# AstNode.InsertChildAfter方法的具体用法?C# AstNode.InsertChildAfter怎么用?C# AstNode.InsertChildAfter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AstNode
的用法示例。
在下文中一共展示了AstNode.InsertChildAfter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
}
}
示例2: AddConstraints
void AddConstraints(AstNode parent, TypeParameters d)
{
if (d == null)
return;
for (int i = 0; i < d.Count; i++) {
var typeParameter = d [i];
if (typeParameter == null)
continue;
var c = typeParameter.Constraints;
if (c == null)
continue;
var location = LocationsBag.GetLocations(c);
var constraint = new Constraint();
constraint.AddChild(new CSharpTokenNode(Convert(c.Location), Roles.WhereKeyword), Roles.WhereKeyword);
constraint.AddChild(new SimpleType(Identifier.Create(c.TypeParameter.Value, Convert(c.TypeParameter.Location))), Roles.ConstraintTypeParameter);
if (location != null)
constraint.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.Colon), Roles.Colon);
var commaLocs = LocationsBag.GetLocations(c.ConstraintExpressions);
int curComma = 0;
if (c.ConstraintExpressions != null) {
foreach (var expr in c.ConstraintExpressions) {
constraint.AddChild(ConvertToType(expr), Roles.BaseType);
var sce = expr as SpecialContraintExpr;
if (sce != null) {
switch (sce.Constraint) {
case SpecialConstraint.Class:
break;
case SpecialConstraint.Struct:
break;
case SpecialConstraint.Constructor:
var bl = LocationsBag.GetLocations(expr);
if (bl != null) {
constraint.AddChild(new CSharpTokenNode(Convert(bl [0]), Roles.LPar), Roles.LPar);
constraint.AddChild(new CSharpTokenNode(Convert(bl [1]), Roles.RPar), Roles.RPar);
}
break;
}
}
if (commaLocs != null && curComma < commaLocs.Count)
constraint.AddChild(new CSharpTokenNode(Convert(commaLocs [curComma++]), Roles.Comma), Roles.Comma);
}
}
// We need to sort the constraints by position; as they might be in a different order than the type parameters
AstNode prevSibling = parent.LastChild;
while (prevSibling.StartLocation > constraint.StartLocation && prevSibling.PrevSibling != null)
prevSibling = prevSibling.PrevSibling;
parent.InsertChildAfter(prevSibling, constraint, Roles.Constraint);
}
}