本文整理汇总了C#中AstNode.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# AstNode.Remove方法的具体用法?C# AstNode.Remove怎么用?C# AstNode.Remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AstNode
的用法示例。
在下文中一共展示了AstNode.Remove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MangleStatement
private void MangleStatement(AstNodeCollection<Statement> statements, AstNode node)
{
// Remove stray semicolons
if (node is EmptyStatement) {
node.Remove();
return;
}
// Inline nested block statements
var block = node as BlockStatement;
if (block != null) {
foreach (var replacement in block.Statements) {
replacement.Remove();
statements.InsertBefore((Statement)node, replacement);
}
node.Remove();
return;
}
// Merge adjacent variable declarations
var declaration = node as VariableDeclarationStatement;
if (declaration != null) {
var previous = PreviousSiblingIgnoringWhitespace(node) as VariableDeclarationStatement;
if (previous != null) {
foreach (var variable in declaration.Variables) {
variable.Remove();
previous.Variables.Add(variable);
}
if (node.PrevSibling is NewLineNode) {
node.PrevSibling.Remove();
}
node.Remove();
}
return;
}
// Bring previous variable declarations into for loops
var loop = node as ForStatement;
if (loop != null) {
var previous = PreviousSiblingIgnoringWhitespace(node) as VariableDeclarationStatement;
if (previous != null) {
var count = loop.Initializers.Count;
if (count == 0) {
previous.Remove();
loop.Initializers.Add(previous);
} else if (count == 1) {
var initializers = loop.Initializers.FirstOrNullObject() as VariableDeclarationStatement;
if (initializers != null) {
foreach (var variable in initializers.Variables) {
variable.Remove();
previous.Variables.Add(variable);
}
previous.Remove();
initializers.Remove();
loop.Initializers.Add(previous);
}
}
}
return;
}
}