Exemple #1
0
 protected abstract void GenerateConditionStatement(System.CodeDom.CodeConditionStatement e);
Exemple #2
0
        public static System.CodeDom.CodeConditionStatement BreakCodeStatement(System.CodeDom.CodeTypeDeclaration codeClass, System.CodeDom.CodeStatementCollection codeStatementCollection, Guid debuggerId, Guid breakId)
        {
            if (debuggerId == Guid.Empty || breakId == Guid.Empty)
            {
                throw new InvalidOperationException();
            }
            //var ret = new System.CodeDom.CodeConditionStatement();
            //ret.Condition = new System.CodeDom.CodePrimitiveExpression(false);
            //return ret;

            var breakEnalbeVariableName = "BreakEnable_" + EngineNS.Editor.Assist.GetValuedGUIDString(breakId);

            System.CodeDom.CodeMemberField member;
            if (!CodeMemberFieldDic.TryGetValue(breakId, out member))
            {
                // 代码:public static bool BreakEnable_XXXXX = false;
                member                = new System.CodeDom.CodeMemberField(typeof(bool), breakEnalbeVariableName);
                member.Attributes     = System.CodeDom.MemberAttributes.Public | System.CodeDom.MemberAttributes.Static;
                member.InitExpression = new System.CodeDom.CodePrimitiveExpression(false);
                codeClass.Members.Add(member);
                CodeMemberFieldDic.Add(breakId, member);
            }
            else
            {
                if (!codeClass.Members.Contains(member))
                {
                    codeClass.Members.Add(member);
                }
            }

            // 代码: if(BreakEnable_XXXXX)
            //       {
            //          var breakContext = new EngineNS.Editor.Runner.RunnerManager.BreakContext();
            //
            //          EngineNS.Editor.Runner.RunnerManager.Instance.Break(breakContext);
            //       }
            var conditionSt = new System.CodeDom.CodeConditionStatement();

            conditionSt.Condition = new System.CodeDom.CodeVariableReferenceExpression(breakEnalbeVariableName);

            var breakContextVarName = "breakContext";
            var breakContextType    = typeof(EngineNS.Editor.Runner.RunnerManager.BreakContext);

            conditionSt.TrueStatements.Add(new System.CodeDom.CodeVariableDeclarationStatement(breakContextType, breakContextVarName, new System.CodeDom.CodeObjectCreateExpression(breakContextType, new System.CodeDom.CodeExpression[] { })));
            conditionSt.TrueStatements.Add(new System.CodeDom.CodeAssignStatement(
                                               new System.CodeDom.CodeFieldReferenceExpression(
                                                   new System.CodeDom.CodeVariableReferenceExpression(breakContextVarName), "ThisObject"),
                                               new System.CodeDom.CodeThisReferenceExpression()));

            conditionSt.TrueStatements.Add(new System.CodeDom.CodeAssignStatement(
                                               new System.CodeDom.CodeFieldReferenceExpression(
                                                   new System.CodeDom.CodeVariableReferenceExpression(breakContextVarName), "DebuggerId"),
                                               new System.CodeDom.CodeSnippetExpression("EngineNS.Rtti.RttiHelper.GuidTryParse(\"" + debuggerId.ToString() + "\")")));
            conditionSt.TrueStatements.Add(new System.CodeDom.CodeAssignStatement(
                                               new System.CodeDom.CodeFieldReferenceExpression(
                                                   new System.CodeDom.CodeVariableReferenceExpression(breakContextVarName), "BreakId"),
                                               new System.CodeDom.CodeSnippetExpression("EngineNS.Rtti.RttiHelper.GuidTryParse(\"" + breakId.ToString() + "\")")));
            conditionSt.TrueStatements.Add(new System.CodeDom.CodeAssignStatement(
                                               new System.CodeDom.CodeFieldReferenceExpression(
                                                   new System.CodeDom.CodeVariableReferenceExpression(breakContextVarName), "ClassName"),
                                               new System.CodeDom.CodePrimitiveExpression(codeClass.Name)));
            conditionSt.TrueStatements.Add(new System.CodeDom.CodeAssignStatement(
                                               new System.CodeDom.CodeFieldReferenceExpression(
                                                   new System.CodeDom.CodeVariableReferenceExpression(breakContextVarName), "ValueContext"),
                                               new System.CodeDom.CodeVariableReferenceExpression("mDebuggerContext")));


            var methodExpState = new System.CodeDom.CodeExpressionStatement(
                new CodeGenerateSystem.CodeDom.CodeMethodInvokeExpression(
                    new System.CodeDom.CodeVariableReferenceExpression("EngineNS.Editor.Runner.RunnerManager.Instance"),
                    "Break",
                    new System.CodeDom.CodeExpression[] { new System.CodeDom.CodeVariableReferenceExpression(breakContextVarName) }));

            conditionSt.TrueStatements.Add(methodExpState);
            codeStatementCollection.Add(conditionSt);

            return(conditionSt);
        }