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


C# Statement.Clone方法代码示例

本文整理汇总了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:
//.........这里部分代码省略.........
开发者ID:Yatajga,项目名称:CodeContracts,代码行数:101,代码来源:HelperMethods.cs


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