本文整理汇总了C#中System.Compiler.Statement.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Statement.Clone方法的具体用法?C# Statement.Clone怎么用?C# Statement.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Compiler.Statement
的用法示例。
在下文中一共展示了Statement.Clone方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Visit
/// <summary>
/// Perform subsitution if necessary (create fresh nodes)
/// </summary>
internal Statement Visit(Statement statement)
{
Contract.Requires(this.IsValid);
Contract.Requires(this.Depth >= 0);
Contract.Ensures(this.Depth >= -1);
if (statement == null) return null;
switch (statement.NodeType)
{
case NodeType.Nop:
case NodeType.Rethrow:
case NodeType.EndFilter:
case NodeType.EndFinally:
break;
case NodeType.Pop:
// a pop statement rather than expression
this.Depth--;
if (this.Depth < 0)
{
// we popped the original closure from the stack.
return null;
}
return statement;
case NodeType.AssignmentStatement:
var astmt = (AssignmentStatement) statement.Clone();
astmt.Target = Visit(astmt.Target);
astmt.Source = Visit(astmt.Source);
return astmt;
case NodeType.ExpressionStatement:
var estmt = (ExpressionStatement) statement.Clone();
if (estmt.Expression.NodeType == NodeType.Dup)
{
if (this.Depth == 0)
{
// duping the closure. Do nothing:
return null;
}
// otherwise, leave dup
}
else if (estmt.Expression.NodeType == NodeType.Pop)
{
var unary = estmt.Expression as UnaryExpression;
if (unary != null && unary.Operand != null)
{
// we are popping the thing we just push, so the depth does not change.
unary = (UnaryExpression) unary.Clone();
unary.Operand = Visit(unary.Operand);
estmt.Expression = unary;
return estmt;
}
// a pop statement rather than expression
this.Depth--;
if (this.Depth < 0)
{
// we popped the original closure from the stack.
return null;
}
}
else
{
estmt.Expression = Visit(estmt.Expression);
if (!IsVoidType(estmt.Expression.Type))
{
this.Depth++;
}
}
return estmt;
case NodeType.Block:
var block = (Block) statement.Clone();
block.Statements = Visit(block.Statements);
return block;
case NodeType.SwitchInstruction:
var sw = (SwitchInstruction) statement.Clone();
sw.Expression = Visit(sw.Expression);
return sw;
case NodeType.Throw:
var th = (Throw) statement.Clone();
th.Expression = Visit(th.Expression);
return th;
case NodeType.Return:
var ret = (Return) statement.Clone();
ret.Expression = Visit(ret.Expression);
return ret;
default:
//.........这里部分代码省略.........