Example #1
0
 public System.CodeDom.CodeExpression GetReferenceCode(IMethodCompile method, CodeStatementCollection statements, bool forValue)
 {
     if (_pointer != null)
     {
         return(_pointer.GetReferenceCode(method, statements, forValue));
     }
     if (_memberPointer != null)
     {
         return(_memberPointer.GetReferenceCode(method, statements, forValue));
     }
     return(null);
 }
 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);
     }
 }