當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。