示例#1
0
        public static WidgetMap GenerateCreationCode(CodeNamespace cns, CodeTypeDeclaration type, Gtk.Widget w, CodeExpression widgetVarExp, CodeStatementCollection statements, GenerationOptions options, ArrayList warnings)
        {
            statements.Add(new CodeCommentStatement("Widget " + w.Name));
            GeneratorContext ctx = new ProjectGeneratorContext(cns, type, statements, options);

            Stetic.Wrapper.Widget ww = Stetic.Wrapper.Widget.Lookup(w);
            ctx.GenerateCreationCode(ww, widgetVarExp);
            ctx.EndGeneration();
            warnings.AddRange(ctx.Warnings);
            return(ctx.WidgetMap);
        }
     private void SerializeExtender(IDesignerSerializationManager manager, ConstantsExtenderProvider provider, ComponentCollection components, CodeStatementCollection statements)
     
    {
          foreach(IComponent component in components)
           {
               Control control = component as Control;

               if(control != null && (control as Form == null))
                {
                    CodeMethodInvokeExpression methodcall = new CodeMethodInvokeExpression(base.SerializeToExpression(manager, provider), "SetConstants");

                    methodcall.Parameters.Add(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), control.Name));
                 
                    string[] constants = provider.GetConstants(control);

                    if(constants != null)
                     {
                         StringBuilder sb = new StringBuilder();

                         sb.Append("new string[] { ");
                     
                         foreach(string constant in constants)
                         
                    {
                              sb.Append(typeof(T).FullName);
                              sb.Append(".");
                              sb.Append(constant);
                              sb.Append(", ");
                             
                    }

                     
                         sb.Remove(sb.Length - 2, 2);

                         sb.Append(" }");
                     
                         methodcall.Parameters.Add(new CodeSnippetExpression(sb.ToString()));

                        
                }
                    else
                     {
                         methodcall.Parameters.Add(new CodePrimitiveExpression(null));
                        
                }
                 
                    statements.Add(methodcall);

                   
            }
              
        }
         
    }
示例#3
0
        public override bool CreateBlockCodeStatements(BloxBlockEd bdi, CodeStatementCollection statements)
        {
            CodeExpression codeExpression = BloxScriptGenerator.CreateBlockCodeExpression(bdi.contextBlock, typeof(Array));

            if (codeExpression == null)
            {
                return(false);
            }
            statements.Add(new CodeExpressionStatement(new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(BloxUtil)), "ArrayReverse", codeExpression)));
            return(true);
        }
 /// <summary>
 /// Adds a stored proc parameter statement for each column in the tableView. Filtered by the provided predicate.
 /// </summary>
 private static void AddStoredProcParameters(Smo.TableViewBase tableView, CodeStatementCollection statements, string entityInstanceName, Func <Smo.Column, bool> columnFilter)
 {
     foreach (Smo.Column column in tableView.Columns)
     {
         if (columnFilter(column))
         {
             var parameterName = string.Format("@{0}", column.Name);
             statements.Add(new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("database"), "AddInParameter", new CodeExpression[] { new CodeVariableReferenceExpression("command"), new CodePrimitiveExpression(parameterName), new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(DbType)), GetDbTypeString(column.DataType)), new CodePropertyReferenceExpression(new CodeTypeReferenceExpression(entityInstanceName), column.Name) }));
         }
     }
 }
示例#5
0
        public override object Serialize(IDesignerSerializationManager manager, object value)
        {
            /* Associate the component with the serializer in the same manner as with
             *      Deserialize */
            CodeDomSerializer baseClassSerializer = (CodeDomSerializer)manager.
                                                    GetSerializer(typeof(RoundGauge).BaseType, typeof(CodeDomSerializer));

            object codeObject = baseClassSerializer.Serialize(manager, value);

            CodeStatementCollection newCode = new CodeStatementCollection();

            if (codeObject is CodeStatementCollection)
            {
                CodeMethodInvokeExpression invokeExpr;

                CodeStatementCollection statements = (CodeStatementCollection)codeObject;

                // The code statement collection is valid, so add our Begin/EndUpdate calls.
                CodeThisReferenceExpression  thisRef  = new CodeThisReferenceExpression();
                CodeFieldReferenceExpression gaugeRef = new CodeFieldReferenceExpression(thisRef, manager.GetName(value));

                // move the comments and the "new" call
                for (int i = 0; i < 4; i++)
                {
                    newCode.Add(statements[0]);
                    statements.RemoveAt(0);
                }

                // add BeginInvoke
                invokeExpr = new CodeMethodInvokeExpression(gaugeRef, "BeginUpdate");
                newCode.Add(invokeExpr);

                // add the designer-generated code
                newCode.AddRange(statements);

                // add EndUpdate
                invokeExpr = new CodeMethodInvokeExpression(gaugeRef, "EndUpdate");
                newCode.Add(invokeExpr);
            }
            return(newCode);
        }
示例#6
0
        public void EmitInterpolationSettings(CodeExpression expr, CodeStatementCollection statements)
        {
            PropertyStateSettings   s = Decorator.Definition.StateAssetSettings;
            PropertyCommandSettings c = Decorator.Definition.CommandAssetSettings;

            if (s != null)
            {
                if (s.SmoothingAlgorithm != SmoothingAlgorithms.None)
                {
                    statements.Add(expr.Call("Settings_Interpolation", s.SnapMagnitude.Literal(), true.Literal()));
                }
            }

            if (c != null)
            {
                if (c.SmoothCorrection)
                {
                    statements.Add(expr.Call("Settings_Interpolation", c.SnapMagnitude.Literal(), false.Literal()));
                }
            }
        }
示例#7
0
        protected override CodeStatementCollection Build(Dictionary <int, List <Dictionary <PARAMETER, string> > > parameters
                                                         , List <SqlFormat> sQLs
                                                         , string connection
                                                         , bool isNotCondition
                                                         , List <string> ReferencedAssemblies
                                                         , Type type
                                                         , string query)
        {
            ReferencedAssemblies.Add("LazySQL.dll");
            ReferencedAssemblies.Add("LazySQL.SQLite.dll");
            ReferencedAssemblies.Add("System.Data.SQLite.dll");

            CodeStatementCollection codeStatementCollection = new CodeStatementCollection();

            #region 添加所需零件

            StringBuilderBlueprint stringBuilderBlueprint = new StringBuilderBlueprint();

            SQLLiteTemplateBlueprint sQLiteTemplateBlueprint = new SQLLiteTemplateBlueprint();

            #endregion

            codeStatementCollection.Add(stringBuilderBlueprint.Create());

            codeStatementCollection.Add(sQLiteTemplateBlueprint.Create());

            TryCatchFinallyBlueprint tryCatchFinallyBlueprint = new TryCatchFinallyBlueprint();

            codeStatementCollection.Add(tryCatchFinallyBlueprint.Create(() =>
            {
                CodeStatementCollection tryCodeStatementCollection = new CodeStatementCollection();

                ListBlueprint listBlueprint = new ListBlueprint();

                tryCodeStatementCollection.Add(listBlueprint.Create <SQLiteParameter>());

                Building(isNotCondition
                         , parameters
                         , tryCodeStatementCollection
                         , new SQLiteParamterQuery(listBlueprint)
                         , type
                         , sQLs
                         , stringBuilderBlueprint
                         , query
                         , connection
                         , sQLiteTemplateBlueprint
                         , listBlueprint);

                return(tryCodeStatementCollection);
            }));

            return(codeStatementCollection);
        }
示例#8
0
        /// <summary>
        /// 代码构成模板
        /// </summary>
        /// <param name="isNotCondition"></param>
        /// <param name="parameters"></param>
        /// <param name="tryCodeStatementCollection"></param>
        /// <param name="paramterQuery"></param>
        /// <param name="type"></param>
        /// <param name="sqls"></param>
        /// <param name="stringBuilderBlueprint"></param>
        protected void Building(
            bool isNotCondition
            , Dictionary <int, List <Dictionary <PARAMETER, string> > > parameters
            , CodeStatementCollection tryCodeStatementCollection
            , IParamterQuery paramterQuery
            , Type type
            , List <SqlFormat> sqls
            , StringBuilderBlueprint stringBuilderBlueprint
            , string query
            , string connection
            , ITemplateBlueprint templateBlueprint
            , ListBlueprint listBlueprint)
        {
            Dictionary <string, string> SavePar = new Dictionary <string, string>();

            //按顺序添加SQL语句以及条件语句
            for (int sQLsCount = 0; sQLsCount < sqls.Count; sQLsCount++)
            {
                tryCodeStatementCollection.Add(stringBuilderBlueprint.Append(sqls[sQLsCount].SQLText));
                if (!isNotCondition)
                {
                    int CondiIndex = sqls[sQLsCount].CondiIndex;
                    if (CondiIndex != -1)
                    {
                        CreateCondition(SavePar, CondiIndex, parameters, tryCodeStatementCollection, paramterQuery, sqls, sQLsCount, stringBuilderBlueprint, sqls[sQLsCount].oNDITION_TYPE);
                    }
                }
            }

            //返回值
            ReturnBlueprint returnBlueprint = new ReturnBlueprint();

            switch (query)
            {
            case "select":
                SelectReturn(connection
                             , tryCodeStatementCollection
                             , templateBlueprint
                             , returnBlueprint
                             , stringBuilderBlueprint
                             , listBlueprint);
                break;

            default:
                DefaultReturn(connection
                              , tryCodeStatementCollection
                              , templateBlueprint
                              , returnBlueprint
                              , stringBuilderBlueprint
                              , listBlueprint);
                break;
            }
        }
示例#9
0
        private CodeStatementCollection CreateValueTypeInitialization(CodeExpression propertyExpression, object parentInstance, PropertyDescriptor property)
        {
            // value types (structs) cannot be modified from a property, so we need to create a temp var.
            string tempVariable  = CreateNewVariable(property.PropertyType);
            object propertyValue = property.GetValue(parentInstance);

            CodeStatementCollection statements = new CodeStatementCollection();

            // declare temp var.
            statements.Add(new CodeVariableDeclarationStatement(property.PropertyType, tempVariable, CodeDomTypeFormatter.FormatValue(propertyValue)));

            CodeVariableReferenceExpression varReference = new CodeVariableReferenceExpression(tempVariable);

            // serialize properties of var.
            statements.AddRange(SerializeProperties(varReference, propertyValue));

            // set property to var.
            statements.Add(new CodeAssignStatement(propertyExpression, varReference));

            return(statements);
        }
        /// <include file='doc\ComponentCodeDomSerializer.uex' path='docs/doc[@for="ComponentCodeDomSerializer.SerializeSupportInitialize"]/*' />
        /// <devdoc>
        ///     This emits a method invoke to ISupportInitialize.
        /// </devdoc>
        private void SerializeSupportInitialize(IDesignerSerializationManager manager, CodeStatementCollection statements, object value, string methodName)
        {
            Debug.WriteLineIf(traceSerialization.TraceVerbose, "ComponentCodeDomSerializer::SerializeSupportInitialize");
            Debug.Indent();

            string name = manager.GetName(value);

            if (name == null)
            {
                IReferenceService referenceService = (IReferenceService)manager.GetService(typeof(IReferenceService));
                if (referenceService != null)
                {
                    name = referenceService.GetName(value);
                }
            }

            Debug.WriteLineIf(traceSerialization.TraceVerbose, name + "." + methodName);

            // Assemble a cast to ISupportInitialize, and then invoke the method.
            //
            CodeExpression targetExpr = null;

            IDesignerHost host = (IDesignerHost)manager.GetService(typeof(IDesignerHost));

            if (host != null && host.RootComponent == value)
            {
                targetExpr = new CodeThisReferenceExpression();
            }
            else
            {
                targetExpr = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), name);
            }

            CodeTypeReference             type         = new CodeTypeReference(typeof(ISupportInitialize));
            CodeCastExpression            castExp      = new CodeCastExpression(type, targetExpr);
            CodeMethodReferenceExpression method       = new CodeMethodReferenceExpression(castExp, methodName);
            CodeMethodInvokeExpression    methodInvoke = new CodeMethodInvokeExpression();

            methodInvoke.Method = method;
            CodeExpressionStatement statement = new CodeExpressionStatement(methodInvoke);

            if (methodName == "BeginInit")
            {
                statement.UserData["statement-ordering"] = "begin";
            }
            else
            {
                statement.UserData["statement-ordering"] = "end";
            }

            statements.Add(statement);
            Debug.Unindent();
        }
 /// <summary>
 /// Generates the code from the specified dump table
 /// </summary>
 /// <param name="table">The table.</param>
 internal void GenerateCode(Table table)
 {
     try
     {
         DispatchTablePairs(table, m_KickstarterClass.Members,
                            exp => m_InitStatements.Add(new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(UserData)), "RegisterType", exp)));
     }
     catch (Exception ex)
     {
         m_Logger.LogError(string.Format("Internal error, code generation aborted : {0}", ex));
     }
 }
        public override CodeExpression ExportCode(MethodType method)
        {
            CodeStatementCollection supprtStatements = method.MethodCode.Statements;

            if (!MathNodeVariable.VariableDeclared(supprtStatements, this.CodeVariableName))
            {
                MathNode.Trace("Declare variable {0}", this.TraceInfo);
                supprtStatements.Add(new CodeVariableDeclarationStatement(new CodeTypeReference(VariableType.ObjectType), CodeVariableName, ValueTypeUtil.GetDefaultCodeByType(VariableType.ObjectType)));
            }
            MathNode.Trace("MathNodeVar.ExportCode returns variable reference to {0}", this.CodeVariableName);
            return(new CodeVariableReferenceExpression(this.CodeVariableName));
        }
示例#13
0
        private CodeExpression BuildArray(CodeStatementCollection statements, string name, object value)
        {
            Array  array = (Array)value;
            Type   type  = value.GetType();
            string uniqueVariableName = GetUniqueVariableName(name, statements);
            CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(type.FullName, uniqueVariableName);

            statement.InitExpression = new CodeArrayCreateExpression(type.GetElementType(), array.Length);
            statements.Add(statement);
            CodeVariableReferenceExpression targetObject = new CodeVariableReferenceExpression(uniqueVariableName);
            string str2 = name + "_";

            for (int i = 0; i < array.Length; i++)
            {
                CodeArrayIndexerExpression left = new CodeArrayIndexerExpression(targetObject, new CodeExpression[0]);
                left.Indices.Add(new CodePrimitiveExpression(i));
                CodeExpression right = this.BuildObject(statements, str2 + i.ToString(), array.GetValue(i));
                statements.Add(new CodeAssignStatement(left, right));
            }
            return(targetObject);
        }
示例#14
0
        public async System.Threading.Tasks.Task <CodeVariableReferenceExpression> CreateBlendTree_PoseItemForBlend(CodeTypeDeclaration codeClass, CodeStatementCollection codeStatementCollection, LinkPinControl poseLinkHandle, string itemName, LinkPinControl blendTimeLinkHandle, object defaultValue, GenerateCodeContext_Method context)
        {
            var poseLinkObj          = poseLinkHandle.GetLinkedObject(0, true);
            var truePoseItemForBlend = new CodeVariableDeclarationStatement(typeof(EngineNS.Bricks.Animation.BlendTree.Node.BlendTree_PoseItemForBlend), itemName, new CodeObjectCreateExpression(new CodeTypeReference(typeof(EngineNS.Bricks.Animation.BlendTree.Node.BlendTree_PoseItemForBlend))));

            codeStatementCollection.Add(truePoseItemForBlend);
            var truePoseNodeAssign = new CodeAssignStatement();

            truePoseNodeAssign.Left  = new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(itemName), "PoseNode");
            truePoseNodeAssign.Right = poseLinkObj.GCode_CodeDom_GetSelfRefrence(null, null);
            codeStatementCollection.Add(truePoseNodeAssign);

            var blendTimeEvaluateMethod = await Helper.CreateEvaluateMethod(codeClass, itemName + "_BlendTimeEvaluateMethod", typeof(float), defaultValue, blendTimeLinkHandle, context);

            var blendTimeAssign = new CodeAssignStatement();

            blendTimeAssign.Left  = new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(itemName), "EvaluateBlendTimeFunc");
            blendTimeAssign.Right = new CodeVariableReferenceExpression(blendTimeEvaluateMethod.Name);
            codeStatementCollection.Add(blendTimeAssign);
            return(new CodeVariableReferenceExpression(itemName));
        }
示例#15
0
        private void CallOnProgress(CodeStatementCollection statements, bool increaseTotal = true)
        {
            if (increaseTotal)
            {
                _totalOperations++;
            }

            var methodcall = new CodeMethodInvokeExpression(
                new CodeMethodReferenceExpression(null, "OnProgress"));

            statements.Add(methodcall);
        }
        internal void AddTypeToTypeManager(CodeStatementCollection elementDictionaryStatements, CodeStatementCollection wrapperDictionaryStatements)
        {
            base.AddTypeToTypeManager(elementDictionaryStatements, "elementDictionary");
            string innerTypeFullName = null;

            if (!this.innerTypeName.Contains(this.innerTypeNs))
            {
                innerTypeFullName = string.Concat("global::", this.innerTypeNs, ".", this.innerTypeName);
            }
            CodeExpression[] codeExpressionArray = new CodeExpression[] { CodeDomHelper.Typeof(this.clrTypeInfo.clrFullTypeName), CodeDomHelper.Typeof(innerTypeFullName) };
            wrapperDictionaryStatements.Add(CodeDomHelper.CreateMethodCallFromField("wrapperDictionary", "Add", codeExpressionArray));
        }
示例#17
0
        public override object Serialize(IDesignerSerializationManager manager, object value)
        {
            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if (_codeMap == null)
            {
                _codeMap = new CodeMap(value.GetType(), manager.GetName(value));
            }
            _codeMap.Clear();

            RootContext rootContext = new RootContext(new CodeThisReferenceExpression(), value);

            manager.Context.Push(rootContext);

            this.SerializeComponents(manager, ((IComponent)value).Site.Container.Components, (IComponent)value);

            // Serialize root component
            //
            CodeStatementCollection statements = new CodeStatementCollection();

            statements.Add(new CodeCommentStatement(String.Empty));
            statements.Add(new CodeCommentStatement(manager.GetName(value)));
            statements.Add(new CodeCommentStatement(String.Empty));
            // Note that during the serialization process below ComponentCodeDomSerializer
            // will be invoked to serialize the rootcomponent during expression serialization.
            // It will check for RootContext and return that.
            base.SerializeProperties(manager, statements, value, new Attribute[0]);
            base.SerializeEvents(manager, statements, value, new Attribute[0]);
            _codeMap.Add(statements);

            manager.Context.Pop();
            return(_codeMap.GenerateClass());
        }
        public CodeMethodReturnStatement Return(CodeExpression expr)
        {
            CodeMethodReturnStatement st = new CodeMethodReturnStatement(expr);

            csc.Add(st);
            return(st);
        }
示例#19
0
        protected CodeStatementCollection GetAssignFromByteArrayStatement(MessageSerializedClassInfo classInfo, MessageSerializedPropertyInfo propertyInfo, CodeVariableReferenceExpression currentArrayIndexExpression, CodeExpression fieldLengthExpression)
        {
            CodePropertyReferenceExpression propertyReferenceExpression = new CodePropertyReferenceExpression(new CodeVariableReferenceExpression(TypedObjectFieldName), propertyInfo.PropertyInfo.Name);

            List <CalculatedFieldInfo> calculatedFieldsThatIncludeThisField = GetCalculatedFieldsThatIncludeThisFieldAndRequireVerification(classInfo.CalculatedFields, propertyInfo);

            CodeStatementCollection codeStatementCollection = new CodeStatementCollection();

            CodeExpression assignmentExpression;

            if (calculatedFieldsThatIncludeThisField.Count == 0)
            {
                // If there aren't any calculated fields that depend on this field then typeSerializer.Deserialize can just be called directly
                //assignmentExpression = GetDeserializeTypeExpression(propertyInfo, currentArrayIndexExpression, fieldLengthExpression);
                // _serializerWhatever.Deserialize(bytes, ref currentArrayIndex, length, ref status);
                assignmentExpression = new CodeMethodInvokeExpression(
                    new CodeVariableReferenceExpression(GetSerializerMemberVariableName(propertyInfo)),
                    "Deserialize",
                    new CodeExpression[]
                {
                    new CodeVariableReferenceExpression("bytes"),
                    new CodeDirectionExpression(FieldDirection.Ref, currentArrayIndexExpression),
                    fieldLengthExpression,
                    new CodeDirectionExpression(FieldDirection.Ref, new CodeVariableReferenceExpression("status"))
                });
            }
            else
            {
                // Otherwise we need to call SerializerBase.Deserialize with the arrays that need to have the bytes from this field added
                // so that the calculated field can be recalculated to verify the received value matches.
                // this.Deserialize<TResultType>(_serializerWhatever, bytes, ref currentArrayIndex, length, status, array1, array2);
                List <CodeExpression> argumentsToDeserialize = new List <CodeExpression>()
                {
                    new CodeVariableReferenceExpression(GetSerializerMemberVariableName(propertyInfo)),
                    new CodeVariableReferenceExpression("bytes"),
                    new CodeDirectionExpression(FieldDirection.Ref, currentArrayIndexExpression),
                    fieldLengthExpression,
                    //new CodeDirectionExpression(FieldDirection.Ref, new CodeVariableReferenceExpression("status")),
                    new CodeVariableReferenceExpression("status")
                };
                argumentsToDeserialize.AddRange(calculatedFieldsThatIncludeThisField.Select(item => new CodeVariableReferenceExpression(GetListBytesName(item))));

                assignmentExpression = new CodeMethodInvokeExpression(
                    new CodeThisReferenceExpression(),
                    "Deserialize",
                    argumentsToDeserialize.ToArray());
            }

            codeStatementCollection.Add(new CodeAssignStatement(propertyReferenceExpression, assignmentExpression));

            return(codeStatementCollection);
        }
示例#20
0
        /// <summary>
        ///  This method actually performs the serialization.  When the member is serialized
        ///  the necessary statements will be added to the statements collection.
        /// </summary>
        public override void Serialize(IDesignerSerializationManager manager, object value, MemberDescriptor descriptor, CodeStatementCollection statements)
        {
            ArgumentNullException.ThrowIfNull(manager);
            ArgumentNullException.ThrowIfNull(value);

            if (!(descriptor is EventDescriptor eventToSerialize))
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            ArgumentNullException.ThrowIfNull(statements);

            try
            {
                // If the IEventBindingService is not available, we don't throw - we just don't do anything.
                if (manager.GetService(typeof(IEventBindingService)) is IEventBindingService eventBindings)
                {
                    PropertyDescriptor prop       = eventBindings.GetEventProperty(eventToSerialize);
                    string             methodName = (string)prop.GetValue(value);

                    if (methodName is not null)
                    {
                        Trace("Event {0} bound to {1}", eventToSerialize.Name, methodName);
                        CodeExpression eventTarget = SerializeToExpression(manager, value);
                        TraceWarningIf(eventTarget is null, "Object has no name and no property ref in context so we cannot serialize events: {0}", value);
                        if (eventTarget is not null)
                        {
                            CodeTypeReference            delegateTypeRef = new CodeTypeReference(eventToSerialize.EventType);
                            CodeDelegateCreateExpression delegateCreate  = new CodeDelegateCreateExpression(delegateTypeRef, _thisRef, methodName);
                            CodeEventReferenceExpression eventRef        = new CodeEventReferenceExpression(eventTarget, eventToSerialize.Name);
                            CodeAttachEventStatement     attach          = new CodeAttachEventStatement(eventRef, delegateCreate);

                            attach.UserData[typeof(Delegate)] = eventToSerialize.EventType;
                            statements.Add(attach);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Since we usually go through reflection, don't
                // show what our engine does, show what caused
                // the problem.
                //
                if (e is TargetInvocationException)
                {
                    e = e.InnerException;
                }

                manager.ReportError(new CodeDomSerializerException(string.Format(SR.SerializerPropertyGenFailed, eventToSerialize.Name, e.Message), manager));
            }
        }
        public CodeStatementCollection GenerateEndActivityInvocationCode(TibcoBWProcess tibcoBwProcessToGenerate)
        {
            var statements = new CodeStatementCollection();

            var returnType = this.GenerateStartMethodReturnType(tibcoBwProcessToGenerate);

            if (returnType.BaseType != CSharpTypeConstant.SystemVoid)
            {
                //statements.AddRange(DefaultActivityBuilder.LogActivity(tibcoBwProcessToGenerate.EndActivity));
                statements.AddRange(new XslBuilder(new XpathBuilder()).Build(TargetAppNameSpaceService.myAppName() + "." + tibcoBwProcessToGenerate.InputAndOutputNameSpace, tibcoBwProcessToGenerate.EndActivity.InputBindings));
                var returnName = tibcoBwProcessToGenerate.EndActivity.Parameters[0].Name;

                var returnStatement = new CodeMethodReturnStatement(new CodeVariableReferenceExpression(returnName));
                statements.Add(returnStatement);
            }
            else
            {
                statements.Add(new CodeMethodReturnStatement());
            }

            return(statements);
        }
 private void FillJSONArrayMembers(CodeStatementCollection statements)
 {
     if (IsComplexType())
     {
         statements.Add(
             new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("result"), "Add",
                                            new CodeMethodInvokeExpression(null, methodName,
                                                                           new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("jsonArray"), "GetJSONObject", new CodeSnippetExpression("i")))));
     }
     else if (IsEnum())
     {
         statements.Add(
             new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("result"), "Add",
                                            new CodeCastExpression(type.FullName,
                                                                   new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("jsonArray"), "OptLong", new CodeSnippetExpression("i")))));
     }
     else
     {
         //should not happens
         throw new NotImplementedException();
     }
 }
示例#23
0
        internal static CodeStatementCollection ParseStatements(IEnumerable <Token> tokenizer, bool includeComments = false)
        {
            var pc = new _PC(tokenizer);

            pc.Advance(false);
            var result = new CodeStatementCollection();

            while (!pc.IsEnded && ST.rbrace != pc.SymbolId)
            {
                result.Add(_ParseStatement(pc, includeComments));
            }
            return(result);
        }
    private static void ConstructMethod(CodeTypeDeclaration myClass, DescriptorProto message, Dictionary <CodeMemberField, FieldDescriptorProto> fieldInfo)
    {
        //Add Construct Method
        CodeStatementCollection constructerStatements = new CodeStatementCollection();

        foreach (CodeTypeMember field in myClass.Members)
        {
            if (field is CodeMemberField)
            {
                CodeMemberField      curField             = field as CodeMemberField;
                FieldDescriptorProto fieldDescriptorProto = fieldInfo[curField];
                var    leftVariable = new CodeVariableReferenceExpression(curField.Name);
                string rightVariableString;
                if (fieldDescriptorProto.Label.Equals(FieldDescriptorProto.Types.Label.LABEL_REPEATED))
                {
                    rightVariableString = $"new {curField.Type.BaseType}()";
                }
                else
                {
                    rightVariableString = GenerateInitialString(fieldDescriptorProto, curField.Type.BaseType);
                }
                constructerStatements.Add(new CodeAssignStatement(leftVariable, new CodeSnippetExpression(rightVariableString)));
            }
        }

        //读取oneof
        if (message.UnknownFields[8].LengthDelimitedList.Count > 0)
        {
            foreach (var oneOfMessage in message.UnknownFields[8].LengthDelimitedList)
            {
                string str         = oneOfMessage.ParseString();
                string name        = str.ToCamel();
                string finalString = $"{message.Name}.{name}OneofCase";
                constructerStatements.Add(new CodeAssignStatement(new CodeSnippetExpression(name), new CodeSnippetExpression($"({finalString})0")));
            }
        }

        AddCodeConstructor(myClass, ToWrapperString(message.Name), constructerStatements);
    }
示例#25
0
        private CodeExpression GetTableArgExpression(
            DataTable tableArg,
            CodeStatementCollection statements,
            ParameterSubstitution paramToIdentifier,
            TableRow parametersRow)
        {
            if (tableArg == null)
            {
                return(new CodeCastExpression(typeof(Table), new CodePrimitiveExpression(null)));
            }

            _tableCounter++;

            //TODO[Gherkin3]: remove dependency on having the first row as header
            var header = tableArg.Rows.First();
            var body   = tableArg.Rows.Skip(1).ToArray();

            //Table table0 = new Table(header...);
            var tableVar = new CodeVariableReferenceExpression("table" + _tableCounter);

            statements.Add(
                new CodeVariableDeclarationStatement(typeof(Table), tableVar.VariableName,
                                                     new CodeObjectCreateExpression(
                                                         typeof(Table),
                                                         GetStringArrayExpression(header.Cells.Select(c => c.Value), paramToIdentifier, null))));

            foreach (var row in body)
            {
                //table0.AddRow(cells...);
                statements.Add(
                    new CodeMethodInvokeExpression(
                        tableVar,
                        "AddRow",
                        GetStringArrayExpression(row.Cells.Select(cell => GetCellValue(cell, paramToIdentifier, parametersRow)), paramToIdentifier,
                                                 null)));
            }

            return(tableVar);
        }
        private void SerializeLoadComponentSettings(IDesignerSerializationManager manager, CodeStatementCollection statements, CodeExpression valueExpression, object value)
        {
            CodeTypeReference             targetType   = new CodeTypeReference(typeof(IPersistComponentSettings));
            CodeCastExpression            targetObject = new CodeCastExpression(targetType, valueExpression);
            CodeMethodReferenceExpression expression2  = new CodeMethodReferenceExpression(targetObject, "LoadComponentSettings");
            CodeMethodInvokeExpression    expression   = new CodeMethodInvokeExpression {
                Method = expression2
            };
            CodeExpressionStatement statement = new CodeExpressionStatement(expression);

            statement.UserData["statement-ordering"] = "end";
            statements.Add(statement);
        }
        void AddStmt(CodeExpression expr)
        {
            if (codeStack.Count == 0)
            {
                return;
            }
            CodeStatementCollection stmtCollection = codeStack.Peek();

            if (stmtCollection != null)
            {
                stmtCollection.Add(expr);
            }
        }
示例#28
0
        public static CodeConstructor CreateXRootFunctionalConstructor(string typeName)
        {
            CodeConstructor constructor = CodeDomHelper.CreateConstructor(MemberAttributes.Public);

            constructor.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeName), "root"));
            CodeStatementCollection      statements = constructor.Statements;
            CodeFieldReferenceExpression codeFieldReferenceExpression = new CodeFieldReferenceExpression(CodeDomHelper.This(), "doc");

            CodeExpression[] codePropertyReferenceExpression = new CodeExpression[] { new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("root"), "Untyped") };
            statements.Add(new CodeAssignStatement(codeFieldReferenceExpression, new CodeObjectCreateExpression("XDocument", codePropertyReferenceExpression)));
            constructor.Statements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(CodeDomHelper.This(), "rootObject"), new CodeVariableReferenceExpression("root")));
            return(constructor);
        }
        /// <summary>
        /// assign value to a variable. declare it if not already eclared
        /// </summary>
        /// <param name="supprtStatements"></param>
        /// <param name="var"></param>
        /// <param name="code"></param>
        public static void AssignVariable(CodeStatementCollection supprtStatements, IVariable var, CodeExpression code)
        {
            if (var is MathNodeVariableDummy)
            {
                MathNode.Trace("Assign dummy variable {0} becomes code statement {1}", var.TraceInfo, code);
                supprtStatements.Add(new CodeExpressionStatement(code));
                return;
            }
            if (var.VariableType.IsLibType)
            {
                if (var.VariableType.LibType.Equals(typeof(void)))
                {
                    MathNode.Trace("Assign void variable {0} becomes code statement {1}", var.TraceInfo, code);
                    supprtStatements.Add(new CodeExpressionStatement(code));
                    return;
                }
            }
            CodeVariableDeclarationStatement cv;

            for (int i = 0; i < supprtStatements.Count; i++)
            {
                if (supprtStatements[i] is CodeVariableDeclarationStatement)
                {
                    cv = (CodeVariableDeclarationStatement)supprtStatements[i];
                    if (cv.Name == var.CodeVariableName)
                    {
                        MathNode.Trace("Assign variable {0}={1}", var.TraceInfo, code);
                        CodeAssignStatement cs = new CodeAssignStatement(
                            new CodeVariableReferenceExpression(var.CodeVariableName),
                            code);
                        supprtStatements.Add(cs);
                        return;
                    }
                }
            }
            MathNode.Trace("Declare and assign variable {0}={1}", var.TraceInfo, code);
            cv = new CodeVariableDeclarationStatement(new CodeTypeReference(var.VariableType.Type), var.CodeVariableName, code);
            supprtStatements.Add(cv);
        }
示例#30
0
        private CodeExpression BuildArray(CodeStatementCollection statements, string name, object value)
        {
            Array  array1 = (Array)value;
            Type   type1  = value.GetType();
            string text1  = GetUniqueVariableName(name, statements);
            CodeVariableDeclarationStatement statement1 = new CodeVariableDeclarationStatement(type1.FullName, text1);

            statement1.InitExpression = new CodeArrayCreateExpression(type1.GetElementType(), array1.Length);
            statements.Add(statement1);
            CodeVariableReferenceExpression expression1 = new CodeVariableReferenceExpression(text1);
            string text2 = name + "_";

            for (int num1 = 0; num1 < array1.Length; num1++)
            {
                CodeArrayIndexerExpression expression2 =
                    new CodeArrayIndexerExpression(expression1, new CodeExpression[0]);
                expression2.Indices.Add(new CodePrimitiveExpression(num1));
                CodeExpression expression3 = BuildObject(statements, text2 + num1.ToString(), array1.GetValue(num1));
                statements.Add(new CodeAssignStatement(expression2, expression3));
            }
            return(expression1);
        }