public void GenerateCodeFromExpression(
     System.CodeDom.CodeExpression e
     , System.IO.TextWriter w
     , System.CodeDom.Compiler.CodeGeneratorOptions o)
 {
     throw new System.NotImplementedException();
 }
Exemple #2
0
        /// <summary>
        /// BaseRuleSetFilterExpressionProvider must interpret all collection expression to string call
        /// one of methods ( ValidateAll, ValidateAny, ConditionCollectionCount ) with CodeExpression for one of collection item
        /// Example: ConditionCollectionAll(this.CustomerAccount.Addresses, "this.Organization == "Org1" && this.Line1 = "line"")
        /// exactly second parameter must be converted to CodeExpression statement by Parser in provider.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="codeExpr">The code expr.</param>
        /// <example>ConditionCollectionAll(this.CustomerAccount.Addresses, "this.Organization == \"Org1\" && this.Line1 = \"line\"");</example>
        /// <returns></returns>
        private static bool PredicateFunction(object item, System.CodeDom.CodeExpression codeExpr)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (codeExpr == null)
            {
                throw new ArgumentNullException("codeExpr");
            }

            bool    retVal = false;
            RuleSet rs     = new RuleSet();
            Rule    rule   = new Rule("collection expression rule");

            RuleExpressionCondition cond       = new RuleExpressionCondition(codeExpr);
            RuleValidation          validation = new RuleValidation(item.GetType(), null);

            rule.Condition = cond;
            rs.Rules.Add(rule);
            rs.Validate(validation);
            if (validation.Errors.Count > 0)
            {
                throw new Exception("Error count " + validation.Errors.Count);
            }
            RuleExecution execution = new RuleExecution(validation, item);

            retVal = cond.Evaluate(execution);

            return(retVal);
        }
Exemple #3
0
        /// <summary>
        /// Returns true if any of the items in the collection satisfies the specified condition.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <param name="codeExpr">The code expr.</param>
        /// <returns></returns>
        public bool ValidateAny(IEnumerable collection, System.CodeDom.CodeExpression codeExpr)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }
            if (codeExpr == null)
            {
                throw new ArgumentNullException("codeExpr");
            }

            bool retVal = false;

            foreach (object item in collection)
            {
                if (PredicateFunction(item, codeExpr))
                {
                    retVal = true;
                    break;
                }
            }

            return(retVal);
            //return collection.Any(x => PredicateFunction(x, codeExpr));
        }
Exemple #4
0
        /// <summary>
        /// Returns true if all of the items in the collection satisfies the specified condition.
        /// </summary>
        /// <remarks>
        /// Returns false if collection does not contain any elements.
        /// </remarks>
        /// <param name="collection">The collection.</param>
        /// <param name="codeExpr">The code expr.</param>
        /// <returns></returns>
        public bool ValidateAll(IEnumerable collection, System.CodeDom.CodeExpression codeExpr)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }
            if (codeExpr == null)
            {
                throw new ArgumentNullException("codeExpr");
            }

            bool retVal = false;             // will return false if no items in the collection

            foreach (object item in collection)
            {
                // Set to true, since we found some items in the collection
                retVal = true;
                if (!PredicateFunction(item, codeExpr))
                {
                    retVal = false;
                    break;
                }
            }
            return(retVal);
            //return collection.All(x => PredicateFunction(x, codeExpr));
        }
        public void ConstructWithParametersNameInitExpressionTest()
        {
            var name           = "Value of name";
            var initExpression = new System.CodeDom.CodeExpression();
            var testObject     = new ImplicitVariableDeclarationStatement(name, initExpression);

            new ImplicitVariableDeclarationStatement(null, initExpression);
            new ImplicitVariableDeclarationStatement(name, null);
        }
        public void ConstructWithParametersNameInitExpressionTest()
        {
            var name = "Value of name";
            var initExpression = new System.CodeDom.CodeExpression();
            var testObject = new ImplicitVariableDeclarationStatement(name, initExpression);

            new ImplicitVariableDeclarationStatement(null, initExpression);
            new ImplicitVariableDeclarationStatement(name, null);
        }
        /// <summary>
        /// Serializes the specified object into a CodeDOM object.
        /// </summary>
        /// <param name="manager">A serialization manager interface that is used during the deserialization process.</param>
        /// <param name="value">The object to serialize.</param>
        /// <returns>A CodeDOM object representing the object that has been serialized.</returns>
        public override object Serialize(IDesignerSerializationManager manager, object value)
        {
            // Set serialization flag
            bool oldSerializationFlag = false;
            SerializationStatus oldSerializationStatus = SerializationStatus.None;

            Chart chart = value as Chart;

            if (chart != null)
            {
                oldSerializationFlag   = chart.serializing;
                oldSerializationStatus = chart.serializationStatus;

                chart.serializing         = true;
                chart.serializationStatus = SerializationStatus.Saving;
            }

            // Serialize object using the base class serializer
            object            result         = null;
            CodeDomSerializer baseSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(Chart).BaseType, typeof(CodeDomSerializer));

            if (baseSerializer != null)
            {
                result = baseSerializer.Serialize(manager, value);

                System.CodeDom.CodeStatementCollection statements = result as System.CodeDom.CodeStatementCollection;

                // Sustom serialization of the DataSource property
                if (statements != null && chart != null)
                {
                    // Check if DataSource property is set
                    if (chart.DataSource != null && chart.DataSource is String && ((String)chart.DataSource) != "(none)")
                    {
                        // Add assignment statement for the DataSource property
                        System.CodeDom.CodeExpression targetObject =
                            base.SerializeToExpression(manager, value);
                        if (targetObject != null)
                        {
                            System.CodeDom.CodeAssignStatement assignStatement = new System.CodeDom.CodeAssignStatement(
                                new System.CodeDom.CodePropertyReferenceExpression(targetObject, "DataSource"),
                                new System.CodeDom.CodePropertyReferenceExpression(new System.CodeDom.CodeThisReferenceExpression(), (String)chart.DataSource));
                            statements.Add(assignStatement);
                        }
                    }
                }
            }

            // Clear serialization flag
            if (chart != null)
            {
                chart.serializing         = oldSerializationFlag;
                chart.serializationStatus = oldSerializationStatus;
            }

            return(result);
        }
Exemple #8
0
 public CodeCastExpression(string targetTypeStr, bool isValueType, System.CodeDom.CodeExpression expression)
 {
     if (string.IsNullOrEmpty(targetTypeStr))
     {
         throw new InvalidOperationException("targetTypeStr is null");
     }
     TargetTypeStr = targetTypeStr;
     Expression    = expression;
     mIsValueType  = isValueType;
 }
Exemple #9
0
 public CodeCastExpression(Type targetType, System.CodeDom.CodeExpression expression)
 {
     if (targetType == null)
     {
         throw new InvalidOperationException("targetType is null");
     }
     mTargetType   = targetType;
     mIsValueType  = mTargetType.IsValueType;
     TargetTypeStr = EngineNS.Rtti.RttiHelper.GetAppTypeString(targetType);
     Expression    = expression;
 }
Exemple #10
0
        /// <summary>
        /// Gets the collection sum.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="codeExpr">The code expr.</param>
        /// <returns></returns>
        public Decimal GetCollectionSum(IEnumerable collection, string fieldName, System.CodeDom.CodeExpression codeExpr)
        {
            //All digist types convert to Decimal withouts miss value if overflow not occurs
            Decimal      retVal = Decimal.Zero;
            PropertyInfo pi     = null;

            string[] indexProperty = null;
            foreach (object item in collection)
            {
                object propertyValue = null;
                if (pi == null)
                {
                    //Get item type once
                    Type itemType = item.GetType();
                    //Try get from property by name
                    pi = itemType.GetProperty(fieldName, BindingFlags.Public | BindingFlags.Instance);
                    if (pi == null)
                    {
                        //Try get from indexer property by name
                        pi            = itemType.GetProperty("Item");
                        indexProperty = new string[] { fieldName };
                    }
                }

                if (pi != null)
                {
                    propertyValue = pi.GetValue(item, indexProperty);

                    if (propertyValue != null && PredicateFunction(item, codeExpr))
                    {
                        try
                        {
                            retVal += Convert.ToDecimal(propertyValue);
                        }
                        catch (InvalidCastException)
                        {
                        }
                    }
                }
            }

            return(retVal);
        }
Exemple #11
0
        /// <summary>
        /// Returns the number of items that satisfied the specified condition.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <param name="codeExpr">The code expr.</param>
        /// <returns></returns>
        public int GetValidatedCount(IEnumerable collection, System.CodeDom.CodeExpression codeExpr)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }
            if (codeExpr == null)
            {
                throw new ArgumentNullException("codeExpr");
            }
            int retVal = 0;

            foreach (object item in collection)
            {
                if (PredicateFunction(item, codeExpr))
                {
                    retVal++;
                }
            }
            return(retVal);
            //return collection.Where(x => PredicateFunction(x, codeExpr)).Count();
        }
Exemple #12
0
        public override async System.Threading.Tasks.Task GCode_CodeDom_GenerateCode(System.CodeDom.CodeTypeDeclaration codeClass, System.CodeDom.CodeStatementCollection codeStatementCollection, CodeGenerateSystem.Base.LinkPinControl element, CodeGenerateSystem.Base.GenerateCodeContext_Method context)
        {
            if (!mCtrlValue1.HasLink || !mCtrlValue2.HasLink)
            {
                return;
            }

            // 计算结果
            if (!context.Method.Statements.Contains(mVariableDeclaration))
            {
                var valueType = GCode_GetTypeString(mCtrlResultLink, context);
                var type      = EngineNS.Rtti.RttiHelper.GetTypeFromTypeFullName(valueType);
                mVariableDeclaration = new System.CodeDom.CodeVariableDeclarationStatement(
                    valueType,
                    GCode_GetValueName(mCtrlResultLink, context),
                    CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(type));
                context.Method.Statements.Insert(0, mVariableDeclaration);
            }

            // 参数1
            var linkObj1 = mCtrlValue1.GetLinkedObject(0, true);
            var linkElm1 = mCtrlValue1.GetLinkedPinControl(0, true);

            if (!linkObj1.IsOnlyReturnValue)
            {
                await linkObj1.GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, linkElm1, context);
            }

            System.CodeDom.CodeExpression valueExp1 = null;
            var valueType1Str = linkObj1.GCode_GetTypeString(linkElm1, context);
            var valueType1    = linkObj1.GCode_GetType(linkElm1, context);

            if (CSParam.ConstructParam == "&&" || CSParam.ConstructParam == "||")
            {
                valueType1Str = "System.Boolean";
                valueType1    = typeof(bool);
            }
            if (linkObj1.Pin_UseOrigionParamName(linkElm1))
            {
                if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Bool)
                {
                    valueExp1 = linkObj1.GCode_CodeDom_GetValue(linkElm1, context);
                }
                else if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Class)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj1.GCode_CodeDom_GetValue(linkElm1, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityInequality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(null));
                    valueExp1 = condition;
                }
                else
                {
                    valueExp1 = linkObj1.GCode_CodeDom_GetValue(linkElm1, context);
                }
            }
            else
            {
                var tempValueName1 = "arithmetic_" + EngineNS.Editor.Assist.GetValuedGUIDString(this.Id) + "_Value1";
                if (!context.Method.Statements.Contains(mVariableDeclarationStatement_Value1))
                {
                    mVariableDeclarationStatement_Value1 = new System.CodeDom.CodeVariableDeclarationStatement(
                        valueType1Str,
                        tempValueName1,
                        CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(EngineNS.Rtti.RttiHelper.GetTypeFromTypeFullName(valueType1Str)));
                    context.Method.Statements.Insert(0, mVariableDeclarationStatement_Value1);
                }


                if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Bool)
                {
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName1),
                                                    linkObj1.GCode_CodeDom_GetValue(linkElm1, context)));
                }
                else if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Class)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj1.GCode_CodeDom_GetValue(linkElm1, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityInequality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(null));
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName1),
                                                    condition));
                }
                else
                {
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName1),
                                                    linkObj1.GCode_CodeDom_GetValue(linkElm1, context)));
                }
                valueExp1 = new System.CodeDom.CodeVariableReferenceExpression(tempValueName1);
            }
            //var valueExp1 = linkObj1.GCode_CodeDom_GetValue(linkElm1, context);

            // 参数2
            var linkObj2 = mCtrlValue2.GetLinkedObject(0, true);
            var linkElm2 = mCtrlValue2.GetLinkedPinControl(0, true);

            if (!linkObj2.IsOnlyReturnValue)
            {
                await linkObj2.GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, linkElm2, context);
            }

            System.CodeDom.CodeExpression valueExp2 = null;
            var valueType2Str = linkObj2.GCode_GetTypeString(linkElm2, context);
            var valueType2    = linkObj2.GCode_GetType(linkElm2, context);

            if (CSParam.ConstructParam == "&&" || CSParam.ConstructParam == "||")
            {
                valueType2Str = "System.Boolean";
                valueType2    = typeof(bool);
            }
            if (linkObj2.Pin_UseOrigionParamName(linkElm2))
            {
                if (linkElm2.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Bool)
                {
                    valueExp2 = linkObj2.GCode_CodeDom_GetValue(linkElm2, context);
                }
                else if (linkElm2.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Class)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj2.GCode_CodeDom_GetValue(linkElm2, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityInequality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(null));
                    valueExp2 = condition;
                }
                else
                {
                    valueExp2 = linkObj2.GCode_CodeDom_GetValue(linkElm2, context);
                }
            }
            else
            {
                var tempValueName2 = "arithmetic_" + EngineNS.Editor.Assist.GetValuedGUIDString(this.Id) + "_Value2";
                if (!context.Method.Statements.Contains(mVariableDeclarationStatement_Value2))
                {
                    mVariableDeclarationStatement_Value2 = new System.CodeDom.CodeVariableDeclarationStatement(
                        valueType2Str,
                        tempValueName2,
                        CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(EngineNS.Rtti.RttiHelper.GetTypeFromTypeFullName(valueType2Str)));
                    context.Method.Statements.Insert(0, mVariableDeclarationStatement_Value2);
                }


                if (linkElm2.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Bool)
                {
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName2),
                                                    linkObj2.GCode_CodeDom_GetValue(linkElm2, context)));
                }
                else if (linkElm2.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Class)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj2.GCode_CodeDom_GetValue(linkElm2, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityInequality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(null));
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName2),
                                                    condition));
                }
                else
                {
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName2),
                                                    linkObj2.GCode_CodeDom_GetValue(linkElm2, context)));
                }
                valueExp2 = new System.CodeDom.CodeVariableReferenceExpression(tempValueName2);
            }
            //var valueExp2 = linkObj2.GCode_CodeDom_GetValue(linkElm2, context);

            // 运算
            var arithmeticExp = new System.CodeDom.CodeBinaryOperatorExpression();

            arithmeticExp.Left  = valueExp1;
            arithmeticExp.Right = valueExp2;
            switch (CSParam.ConstructParam)
            {
            case "+":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.Add;
                break;

            case "-":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.Subtract;
                break;

            case "×":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.Multiply;
                break;

            case "÷":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.Divide;
                break;

            case "&&":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.BooleanAnd;
                break;

            case "||":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.BooleanOr;
                break;

            case "&":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.BitwiseAnd;
                break;

            case "|":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.BitwiseOr;
                break;
            }

            // 收集用于调试的数据的代码
            var debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);

            if (linkObj1.Pin_UseOrigionParamName(linkElm1))
            {
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValue1.GetLinkPinKeyName(), valueExp1, valueType1Str, context);
            }
            else
            {
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValue1.GetLinkPinKeyName(), valueExp1, valueType1Str, context);
            }
            if (linkObj2.Pin_UseOrigionParamName(linkElm2))
            {
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValue2.GetLinkPinKeyName(), valueExp2, valueType2Str, context);
            }
            else
            {
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValue2.GetLinkPinKeyName(), valueExp2, valueType2Str, context);
            }
            // 调试用代码
            var breakCondStatement = CodeDomNode.BreakPoint.BreakCodeStatement(codeClass, debugCodes, HostNodesContainer.GUID, Id);

            // 设置数据代码
            if (!linkObj1.Pin_UseOrigionParamName(this.mCtrlValue1))
            {
                CodeDomNode.BreakPoint.GetSetDataValueCodeStatement(breakCondStatement.TrueStatements, this.mCtrlValue1.GetLinkPinKeyName(), valueExp1, valueType1);
            }
            if (!linkObj2.Pin_UseOrigionParamName(this.mCtrlValue2))
            {
                CodeDomNode.BreakPoint.GetSetDataValueCodeStatement(breakCondStatement.TrueStatements, this.mCtrlValue2.GetLinkPinKeyName(), valueExp2, valueType2);
            }
            CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);

            if (element == mCtrlResultLink)
            {
                // 创建结果并赋值
                if (mAssignStatement == null)
                {
                    mAssignStatement      = new System.CodeDom.CodeAssignStatement();
                    mAssignStatement.Left = new System.CodeDom.CodeVariableReferenceExpression(GCode_GetValueName(null, context));
                }
                mAssignStatement.Right = arithmeticExp;

                if (codeStatementCollection.Contains(mAssignStatement))
                {
                    //var assign = new System.CodeDom.CodeAssignStatement(GCode_CodeDom_GetValue(null) , arithmeticExp);
                    //codeStatementCollection.Add(assign);
                }
                else
                {
                    codeStatementCollection.Add(mAssignStatement);
                }

                debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, mCtrlResultLink.GetLinkPinKeyName(), GCode_CodeDom_GetValue(mCtrlResultLink, context), GCode_GetTypeString(mCtrlResultLink, context), context);
                CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);
            }
        }
 public virtual void GenerateCodeFromExpression(System.CodeDom.CodeExpression expression, System.IO.TextWriter writer, System.CodeDom.Compiler.CodeGeneratorOptions options)
 {
 }
Exemple #14
0
 void System.CodeDom.Compiler.ICodeGenerator.GenerateCodeFromExpression(System.CodeDom.CodeExpression e, TextWriter w, CodeGeneratorOptions o)
 {
 }
Exemple #15
0
 protected void GenerateExpression(System.CodeDom.CodeExpression e)
 {
 }
 string ExprToStr(System.CodeDom.CodeExpression expr)
 {
     System.CodeDom.CodePrimitiveExpression p = expr as System.CodeDom.CodePrimitiveExpression;
     return(p != null? p.Value as string : null);
 }
 public CodeMethodInvokeExpression(System.CodeDom.CodeExpression targetObject, string methodName, bool useAwait, params System.CodeDom.CodeExpression[] parameters)
 {
     this.method = new System.CodeDom.CodeMethodReferenceExpression(targetObject, methodName);
     Parameters.AddRange(parameters);
     UseAwait = useAwait;
 }
        public override async System.Threading.Tasks.Task GCode_CodeDom_GenerateCode(System.CodeDom.CodeTypeDeclaration codeClass, System.CodeDom.CodeStatementCollection codeStatementCollection, CodeGenerateSystem.Base.LinkPinControl element, CodeGenerateSystem.Base.GenerateCodeContext_Method context)
        {
            if (!mCtrlValue1.HasLink)
            {
                return;
            }

            // 计算结果
            if (!context.Method.Statements.Contains(mVariableDeclaration))
            {
                var valueType = GCode_GetTypeString(mCtrlResultLink, context);
                var type      = EngineNS.Rtti.RttiHelper.GetTypeFromTypeFullName(valueType);
                mVariableDeclaration = new System.CodeDom.CodeVariableDeclarationStatement(
                    valueType,
                    GCode_GetValueName(mCtrlResultLink, context),
                    CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(type));
                context.Method.Statements.Insert(0, mVariableDeclaration);
            }

            // 参数1
            var linkObj1 = mCtrlValue1.GetLinkedObject(0, true);
            var linkElm1 = mCtrlValue1.GetLinkedPinControl(0, true);

            if (!linkObj1.IsOnlyReturnValue)
            {
                await linkObj1.GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, linkElm1, context);
            }

            System.CodeDom.CodeExpression valueExp1 = null;
            var valueType1    = typeof(bool);
            var valueType1Str = valueType1.FullName;

            if (linkObj1.Pin_UseOrigionParamName(linkElm1))
            {
                if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Bool)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj1.GCode_CodeDom_GetValue(linkElm1, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityEquality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(false));
                    valueExp1 = condition;
                }
                else if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Class)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj1.GCode_CodeDom_GetValue(linkElm1, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityEquality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(null));
                    valueExp1 = condition;
                }
            }
            else
            {
                var tempValueName1 = "InverterControl_" + EngineNS.Editor.Assist.GetValuedGUIDString(this.Id) + "_Value1";
                if (!context.Method.Statements.Contains(mVariableDeclarationStatement_Value1))
                {
                    mVariableDeclarationStatement_Value1 = new System.CodeDom.CodeVariableDeclarationStatement(
                        valueType1Str,
                        tempValueName1,
                        CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(EngineNS.Rtti.RttiHelper.GetTypeFromTypeFullName(valueType1Str)));
                    context.Method.Statements.Insert(0, mVariableDeclarationStatement_Value1);
                }


                if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Bool)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj1.GCode_CodeDom_GetValue(linkElm1, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityEquality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(false));
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName1),
                                                    condition));
                }
                else if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Class)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj1.GCode_CodeDom_GetValue(linkElm1, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityEquality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(null));
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName1),
                                                    condition));
                }
                valueExp1 = new System.CodeDom.CodeVariableReferenceExpression(tempValueName1);
            }
            //var valueExp1 = linkObj1.GCode_CodeDom_GetValue(linkElm1, context);

            // 收集用于调试的数据的代码
            var debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);

            if (linkObj1.Pin_UseOrigionParamName(linkElm1))
            {
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValue1.GetLinkPinKeyName(), valueExp1, valueType1Str, context);
            }
            else
            {
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValue1.GetLinkPinKeyName(), valueExp1, valueType1Str, context);
            }
            // 调试用代码
            var breakCondStatement = CodeDomNode.BreakPoint.BreakCodeStatement(codeClass, debugCodes, HostNodesContainer.GUID, Id);

            // 设置数据代码
            if (!linkObj1.Pin_UseOrigionParamName(this.mCtrlValue1))
            {
                CodeDomNode.BreakPoint.GetSetDataValueCodeStatement(breakCondStatement.TrueStatements, this.mCtrlValue1.GetLinkPinKeyName(), valueExp1, valueType1);
            }
            CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);

            if (element == mCtrlResultLink)
            {
                // 创建结果并赋值
                if (mAssignStatement == null)
                {
                    mAssignStatement      = new System.CodeDom.CodeAssignStatement();
                    mAssignStatement.Left = new System.CodeDom.CodeVariableReferenceExpression(GCode_GetValueName(null, context));
                }
                mAssignStatement.Right = valueExp1;

                if (codeStatementCollection.Contains(mAssignStatement))
                {
                    //var assign = new System.CodeDom.CodeAssignStatement(GCode_CodeDom_GetValue(null) , InverterControlExp);
                    //codeStatementCollection.Add(assign);
                }
                else
                {
                    codeStatementCollection.Add(mAssignStatement);
                }

                debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, mCtrlResultLink.GetLinkPinKeyName(), GCode_CodeDom_GetValue(mCtrlResultLink, context), GCode_GetTypeString(mCtrlResultLink, context), context);
                CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);
            }
        }
Exemple #19
0
        public override async System.Threading.Tasks.Task GCode_CodeDom_GenerateCode(System.CodeDom.CodeTypeDeclaration codeClass, System.CodeDom.CodeStatementCollection codeStatementCollection, CodeGenerateSystem.Base.LinkPinControl element, CodeGenerateSystem.Base.GenerateCodeContext_Method context)
        {
            MethodInvokeParameterControl retCtrl = null;
            Dictionary <CodeGenerateSystem.Base.BaseNodeControl, System.CodeDom.CodeExpression> paramCodeExps = new Dictionary <CodeGenerateSystem.Base.BaseNodeControl, System.CodeDom.CodeExpression>();
            var rcParam = CSParam as ReturnCustomConstructParam;

            if (rcParam.MethodInfo.IsAsync)
            {
                // 异步不能有out,只能有一个返回值
                if (mChildNodes.Count == 1)
                {
                    retCtrl = mChildNodes[0] as MethodInvokeParameterControl;
                }
            }
            else
            {
                foreach (var paramNode in mChildNodes)
                {
                    if (paramNode is MethodInvokeParameterControl)
                    {
                        var pm    = paramNode as MethodInvokeParameterControl;
                        var param = pm.CSParam as MethodInvokeParameterControl.MethodInvokeParameterConstructionParams;
                        if (param.ParamInfo.ParamName == "Return")
                        {
                            retCtrl = pm;
                            continue;
                        }
                        if (pm.HasLink())
                        {
                            await pm.GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, pm.ParamPin, context);

                            var exp = new CodeGenerateSystem.CodeDom.CodeCastExpression(param.ParamInfo.ParameterType, pm.GCode_CodeDom_GetValue(pm.ParamPin, context));
                            paramCodeExps[paramNode] = exp;
                            codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                            new System.CodeDom.CodeVariableReferenceExpression(param.ParamInfo.ParamName),
                                                            exp));
                        }
                        else if (mTemplateClassInstance != null)
                        {
                            var    proInfo = mTemplateClassInstance.GetType().GetProperty(param.ParamInfo.ParamName);
                            object proValue;
                            if (proInfo == null)
                            {
                                proValue = CodeGenerateSystem.Program.GetDefaultValueFromType(param.ParamInfo.ParameterType);
                            }
                            else
                            {
                                proValue = proInfo.GetValue(mTemplateClassInstance);
                            }
                            var valueExp = Program.GetValueCode(codeStatementCollection, param.ParamInfo.ParameterType, proValue);
                            paramCodeExps[paramNode] = valueExp;
                            codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(new System.CodeDom.CodeVariableReferenceExpression(param.ParamInfo.ParamName), valueExp));
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                }
            }

            if (retCtrl != null)
            {
                if (retCtrl.HasLink())
                {
                    await retCtrl.GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, retCtrl.ParamPin, context);
                }

                System.CodeDom.CodeExpression retExp = null;
                if (retCtrl.HasLink())
                {
                    var retStatement = new System.CodeDom.CodeMethodReturnStatement();
                    retExp = retCtrl.GCode_CodeDom_GetValue(retCtrl.ParamPin, context);
                    paramCodeExps[retCtrl] = retExp;
                }
                else if (mTemplateClassInstance != null)
                {
                    var    param   = retCtrl.CSParam as MethodInvokeParameterControl.MethodInvokeParameterConstructionParams;
                    var    proInfo = mTemplateClassInstance.GetType().GetProperty(param.ParamInfo.ParamName);
                    object proValue;
                    if (proInfo == null)
                    {
                        proValue = CodeGenerateSystem.Program.GetDefaultValueFromType(param.ParamInfo.ParameterType);
                    }
                    else
                    {
                        proValue = proInfo.GetValue(mTemplateClassInstance);
                    }
                    retExp = Program.GetValueCode(codeStatementCollection, param.ParamInfo.ParameterType, proValue);
                    paramCodeExps[retCtrl] = retExp;
                }

                #region Debug
                var debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);
                foreach (var paramNode in mChildNodes)
                {
                    if (paramNode is MethodInvokeParameterControl)
                    {
                        var pm = paramNode as MethodInvokeParameterControl;
                        System.CodeDom.CodeExpression exp;
                        if (paramCodeExps.TryGetValue(paramNode, out exp))
                        {
                            CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, pm.ParamPin.GetLinkPinKeyName(), exp, pm.GCode_GetTypeString(pm.ParamPin, context), context);
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException("未实现");
                    }
                }
                var breakCondStatement = CodeDomNode.BreakPoint.BreakCodeStatement(codeClass, debugCodes, HostNodesContainer.GUID, Id);
                CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);
                #endregion

                codeStatementCollection.Add(new System.CodeDom.CodeMethodReturnStatement(retExp));
            }
            else
            {
                #region Debug
                var debugCodes         = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);
                var breakCondStatement = CodeDomNode.BreakPoint.BreakCodeStatement(codeClass, debugCodes, HostNodesContainer.GUID, Id);
                CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);
                #endregion
                codeStatementCollection.Add(new System.CodeDom.CodeMethodReturnStatement());
            }
        }
Exemple #20
0
        public static void GetSetDataValueCodeStatement(System.CodeDom.CodeStatementCollection codeStatementCollection, string name, System.CodeDom.CodeExpression valueExp, Type valueType)
        {
            var stat = new System.CodeDom.CodeAssignStatement(
                valueExp,
                new CodeGenerateSystem.CodeDom.CodeCastExpression(
                    valueType,
                    new System.CodeDom.CodeFieldReferenceExpression(
                        new System.CodeDom.CodeVariableReferenceExpression("mDebuggerContext"), name)
                    ));

            codeStatementCollection.Add(stat);
        }
 // Constructors
 public RootContext(System.CodeDom.CodeExpression expression, object value)
 {
 }
 public ExpressionContext(System.CodeDom.CodeExpression expression, Type expressionType, object owner)
 {
 }
Exemple #23
0
 // Methods
 public virtual string GetTargetComponentName(System.CodeDom.CodeStatement statement, System.CodeDom.CodeExpression expression, Type targetType)
 {
 }
 public virtual new void GenerateCodeFromExpression(System.CodeDom.CodeExpression expression, TextWriter writer, CodeGeneratorOptions options)
 {
 }
Exemple #25
0
 protected override object SerializeCollection(IDesignerSerializationManager manager, System.CodeDom.CodeExpression targetExpression, System.Type targetType, System.Collections.ICollection originalCollection, System.Collections.ICollection valuesToSerialize)
 {
     return(base.SerializeCollection(manager, targetExpression, targetType, originalCollection, valuesToSerialize));
 }
Exemple #26
0
        public static void GetGatherDataValueCodeStatement(System.CodeDom.CodeStatementCollection codeStatementCollection, string name, System.CodeDom.CodeExpression valueExp, string valueType, CodeGenerateSystem.Base.GenerateCodeContext_Method context)
        {
            // 指针类型不生成收集代码
            if (valueType.Contains("*"))
            {
                return;
            }

            // 收集debug用数据
            if (!mDebugValueFieldDic.ContainsKey(name))
            {
                var field = new System.CodeDom.CodeMemberField(valueType, name);
                field.Attributes = System.CodeDom.MemberAttributes.Public;
                context.ClassContext.DebugContextClass.Members.Add(field);
                mDebugValueFieldDic[name] = field;
            }

            // 代码: Debugger.XXX = XXX;
            codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                            new System.CodeDom.CodeFieldReferenceExpression(new System.CodeDom.CodeVariableReferenceExpression("mDebuggerContext"), name),
                                            //new CodeGenerateSystem.CodeDom.CodeCastExpression(valueType, valueExp)));
                                            valueExp));

            //// 代码:EngineNS.Editor.Runner.RunnerManager.Instance.GatherDataValue(id, name, value, valueType, canChangeValue)
            //var methodExp = new System.CodeDom.CodeExpressionStatement(
            //                new System.CodeDom.CodeMethodInvokeExpression(
            //                        new System.CodeDom.CodeVariableReferenceExpression("EngineNS.Editor.Runner.RunnerManager.Instance"),
            //                        "GatherDataValue",
            //                        new System.CodeDom.CodeExpression[] {
            //                                                new System.CodeDom.CodeSnippetExpression("EngineNS.Rtti.RttiHelper.GuidTryParse(\"" + id.ToString() + "\")"),
            //                                                new System.CodeDom.CodePrimitiveExpression(name),
            //                                                new CodeGenerateSystem.CodeDom.CodeCastExpression(valueType, valueExp),
            //                                                new System.CodeDom.CodeTypeOfExpression(valueType),
            //                                                new System.CodeDom.CodePrimitiveExpression(canChangeValueWhenDebug),
            //                        }));
            //codeStatementCollection.Add(methodExp);
        }