当前位置: 首页>>代码示例>>C#>>正文


C# Expression.Clone方法代码示例

本文整理汇总了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;
 }
开发者ID:modulexcite,项目名称:SHFB-1,代码行数:28,代码来源:Duplicator.cs

示例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;
            }
开发者ID:Yatajga,项目名称:CodeContracts,代码行数:92,代码来源:HelperMethods.cs

示例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;
		}
开发者ID:dbremner,项目名称:specsharp,代码行数:45,代码来源:CodeFlattener.cs


注:本文中的System.Compiler.Expression.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。