本文整理汇总了C#中System.Compiler.Expression.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.Clone方法的具体用法?C# Expression.Clone怎么用?C# Expression.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Compiler.Expression
的用法示例。
在下文中一共展示了Expression.Clone方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitExpression
public override Expression VisitExpression(Expression expression)
{
if (expression == null) return null;
switch (expression.NodeType)
{
case NodeType.Dup:
case NodeType.Arglist:
expression = (Expression)expression.Clone();
break;
case NodeType.Pop:
UnaryExpression uex = expression as UnaryExpression;
if (uex != null)
{
uex = (UnaryExpression)uex.Clone();
uex.Operand = this.VisitExpression(uex.Operand);
expression = uex;
}
else
expression = (Expression)expression.Clone();
break;
default:
expression = (Expression)this.Visit(expression);
break;
}
if (expression == null) return null;
expression.Type = this.VisitTypeReference(expression.Type);
return expression;
}
示例2: Visit
private Expression Visit(Expression expression)
{
Contract.Requires(this.Depth >= 0);
Contract.Ensures(this.Depth >= 0);
if (this.introducedClosureLocal == null) return expression;
if (expression == null) return null;
switch (expression.NodeType)
{
case NodeType.MemberBinding:
var mb = (MemberBinding) expression.Clone();
mb.TargetObject = Visit(mb.TargetObject);
return mb;
case NodeType.This:
case NodeType.Parameter:
case NodeType.Local:
break;
case NodeType.Pop:
if (this.Depth == 0)
{
return this.introducedClosureLocal;
}
this.Depth--;
break;
case NodeType.Literal:
case NodeType.Arglist:
break;
case NodeType.AddressDereference:
var ad = (AddressDereference) expression.Clone();
ad.Address = Visit(ad.Address);
return ad;
case NodeType.Construct:
var c = (Construct) expression.Clone();
c.Operands = Visit(c.Operands);
return c;
case NodeType.ConstructArray:
var ca = (ConstructArray) expression.Clone();
ca.Operands = Visit(ca.Operands);
return ca;
case NodeType.Call:
case NodeType.Callvirt:
var call = (MethodCall) expression.Clone();
call.Callee = Visit(call.Callee);
call.Operands = Visit(call.Operands);
return call;
case NodeType.Cpblk:
case NodeType.Initblk:
var tern = (TernaryExpression) expression.Clone();
tern.Operand1 = Visit(tern.Operand1);
tern.Operand2 = Visit(tern.Operand2);
tern.Operand3 = Visit(tern.Operand3);
return tern;
case NodeType.Indexer:
var indexer = (Indexer) expression.Clone();
indexer.Object = Visit(indexer.Object);
indexer.Operands = Visit(indexer.Operands);
return indexer;
default:
var binary = expression as BinaryExpression;
if (binary != null)
{
binary = (BinaryExpression) binary.Clone();
binary.Operand1 = Visit(binary.Operand1);
binary.Operand2 = Visit(binary.Operand2);
return binary;
}
var unary = expression as UnaryExpression;
if (unary != null)
{
unary = (UnaryExpression) unary.Clone();
unary.Operand = Visit(unary.Operand);
return unary;
}
throw new NotImplementedException("ClosureNormalization Expression");
}
return expression;
}
示例3: simplify_addressof_operand
/// <summary>
///
/// </summary>
private Expression simplify_addressof_operand(Expression operand)
{
switch(operand.NodeType)
{
case NodeType.This:
case NodeType.Parameter:
case NodeType.Local:
// 1. & variable;
ParameterBinding pb = operand as ParameterBinding;
if (pb != null) {
This tp = pb.BoundParameter as This;
if (tp != null) {
operand = pb = (ParameterBinding)pb.Clone();
pb.BoundParameter = (Parameter)this.VisitThis(tp);
}
}
break;
case NodeType.Indexer:
// 2. & array[index]
operand = (Expression)operand.Clone();
Indexer indexer = (Indexer) operand;
indexer.Object = simplify(indexer.Object);
ExpressionList ops = VisitExpressionList(indexer.Operands);
System.Diagnostics.Debug.Assert(ops != null, "VisitExpressionList must return non-null if arg non-null");
indexer.Operands = ops;
break;
case NodeType.MemberBinding:
// 3. & object.field
operand = (Expression)operand.Clone();
MemberBinding mb = (MemberBinding) operand;
if (mb.TargetObject != null)
{
mb.TargetObject = simplify(mb.TargetObject);
}
break;
default:
throw new ApplicationException("Strange AddressOf expression: ");
}
return operand;
}