public void ExportCode(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, bool debug) { if (IsValid) { CodeExpression ceCondition = null; if (_condition != null) { ceCondition = _condition.ExportCode(methodToCompile); if (ceCondition != null) { ceCondition = CompilerUtil.ConvertToBool(_condition.DataType, ceCondition); } } CodeStatementCollection sts = statements; if (ceCondition != null) { CodeConditionStatement cs = new CodeConditionStatement(); cs.Condition = ceCondition; statements.Add(cs); sts = cs.TrueStatements; } CodeExpression right; if (_valType.ValueType == EnumValueType.ConstantValue) { right = _val.GetReferenceCode(methodToCompile, sts, true); } else { List <CodeExpression> ps = new List <CodeExpression>(); ps.Add(_valType.GetReferenceCode(methodToCompile, sts, true)); if (_val.ConstantValue != null) { CodeExpression[] pp = _val.ConstantValue.GetConstructorParameters(methodToCompile, sts); if (pp != null) { ps.AddRange(pp); } } right = new CodeCastExpression(_var.BaseClassType, new CodeMethodInvokeExpression( new CodeTypeReferenceExpression(typeof(Activator)), "CreateInstance", ps.ToArray()) ); } CodeExpression left = _var.GetReferenceCode(methodToCompile, sts, false); CodeVariableReferenceExpression cvre = left as CodeVariableReferenceExpression; CodeSnippetExpression cse = right as CodeSnippetExpression; if (cvre != null && cse != null && string.CompareOrdinal(cse.Value, string.Format(CultureInfo.InvariantCulture, "{0}++", cvre.VariableName)) == 0) { CodeExpressionStatement ces = new CodeExpressionStatement(right); sts.Add(ces); } else { CodeAssignStatement cas = new CodeAssignStatement(left, right); sts.Add(cas); } } }
public void ExportCode(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, bool debug) { if (IsValid) { CodeExpression ceCondition = null; if (_condition != null) { ceCondition = _condition.ExportCode(methodToCompile); if (ceCondition != null) { ceCondition = CompilerUtil.ConvertToBool(_condition.DataType, ceCondition); } } CodeStatementCollection sts = statements; if (ceCondition != null) { CodeConditionStatement cs = new CodeConditionStatement(); cs.Condition = ceCondition; statements.Add(cs); sts = cs.TrueStatements; } CodeExpression right; if (_valType.ValueType == EnumValueType.ConstantValue) { right = _val.GetReferenceCode(methodToCompile, sts, true); } else { List <CodeExpression> ps = new List <CodeExpression>(); ps.Add(_valType.GetReferenceCode(methodToCompile, sts, true)); if (_val.ConstantValue != null) { CodeExpression[] pp = _val.ConstantValue.GetConstructorParameters(methodToCompile, sts); if (pp != null) { ps.AddRange(pp); } } right = new CodeCastExpression(_var.ObjectType, new CodeMethodInvokeExpression( new CodeTypeReferenceExpression(typeof(Activator)), "CreateInstance", ps.ToArray()) ); } CodeExpression left = _var.GetReferenceCode(methodToCompile, sts, false); CodeAssignStatement cas = new CodeAssignStatement(left, right); sts.Add(cas); } }