public virtual void TryCatchSend(CodeStatementCollection statements, CodeVariableReferenceExpression varrefSendHandle, CodeStatementCollection statementsTrySend)
 {
     CodeTryCatchFinallyStatement trycatchSend = new CodeTryCatchFinallyStatement(
         statementsTrySend.Cast<CodeStatement>().ToArray(),
         new CodeCatchClause[] { },
         new CodeStatement[] // Finally
         {
             // Dispose in finally block.
             new CodeConditionStatement(new CodeBinaryOperatorExpression(varrefSendHandle, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null)),
                 new CodeExpressionStatement(new CodeMethodInvokeExpression(varrefSendHandle, "Dispose"))
             )
         }
     );
     statements.Add(trycatchSend);
 }
        public virtual CodeTryCatchFinallyStatement ReceiveMessage(string methodName, CodeStatementCollection statementsTryRecv)
        {
            CodeTryCatchFinallyStatement trycatchReceive = new CodeTryCatchFinallyStatement(
                new CodeStatement[]
                {
                    // ReceiveMessage
                    this.ReceiveMessage(),
                    // * if (((this.result == 0) && (msgHandleResp != null))) // If received message ok
                    new CodeConditionStatement(
                        new CodeBinaryOperatorExpression(
                            exprResultOk,
                            CodeBinaryOperatorType.BooleanAnd,
                            this.IfResponseHandleNotNull()
                        )
                        ,new CodeStatement[] // True statements
                        {
                            // * if ((msgResp.Data.typefield.type == Udbus.Core.dbus_msg_type.DBUS_TYPE_ERROR))
                            new CodeConditionStatement(
                                this.IfResponseIsDbusError()
                                ,new CodeStatement[]
                                {
                                    // * throw Udbus.Core.Exceptions.UdbusMessageMethodErrorException.Create("<method_name>", this.ConnectionParameters, msgStructResp);
                                    this.ThrowMethodErrorException(methodName)
                                }
                                ,statementsTryRecv.Cast<CodeStatement>().ToArray() // False statements
                            )
                        }
                        ,new CodeStatement[] // False statements
                        {
                            // * throw Udbus.Core.Exceptions.UdbusMethodReceiveException.Create("<method_name>", this.result, this.ConnectionParameters);
                            this.ThrowMethodReceiveException(methodName)
                        }
                    )

                },
                new CodeCatchClause[] { },
                new CodeStatement[] // Finally
                {
                    new CodeConditionStatement(
                        compResponseOk, new CodeExpressionStatement(new CodeMethodInvokeExpression(varrefResponseMessagePair, "Dispose"))
                    )
                }
            );
            return trycatchReceive;
        }
 /// <summary>
 /// Visits a <see cref="CodeStatementCollection"/>.
 /// </summary>
 /// <param name="codeStatementCollection">The <see cref="CodeStatementCollection"/> to visit.</param>
 protected virtual void VisitCodeStatementCollection(CodeStatementCollection codeStatementCollection)
 {
     // Visit all of the CodeStatement items in the collection.
     foreach (CodeStatement item in codeStatementCollection.Cast<CodeStatement>())
     {
         this.VisitCodeStatement(item);
     }
 }
        public virtual void AssignResults(CodeStatementCollection statementsTryRecv
            , CodeConditionStatement condOut, CodeConditionStatement condOutIter
            , CodeStatementCollection stmtsFinishResult, CodeThrowExceptionStatement throwargOutPrev
            
            , string idlMethodName, ref int nOutArgCounter
            )
        {
            if (condOut != null) // If there are out parameters
            {
                if (stmtsFinishResult.Count > 0) // If there's any out result parameters
                {
                    // Assign if successful.
                    condOutIter.TrueStatements.Add(new CodeConditionStatement(
                        // * if (this.result == 0)
                        exprResultOk,
                        stmtsFinishResult.Cast<CodeStatement>().ToArray() // True statements
                        , new CodeStatement[] // False statements
                        {
                            throwargOutPrev
                        }
                    ));

                } // Ends if there's any out result parameters

                // Add the root condition variable.
                statementsTryRecv.Add(condOut);

            } // Ends if there are out parameters
        }
        static public void MakeSignalParameters(CodeTypeDeclaration typedeclArgs,
            CodeTypeFactory codetypefactoryOut,
            Udbus.Parsing.CodeMemberDeferredClassHolder declarationHolder,
            IDLInterface idlIntf,
            string methodName,
            string idlSignalName,
            IList<IDLSignalArgument> arguments,
            CodeParameterDeclarationExpressionCollection parameters,
            CodeStatementCollection statements,
            Udbus.Parsing.BuildContext context,
            MarshalBuilderHelper codebuilder)
        {
            CodeStatementCollection statementsTryRecv = new CodeStatementCollection();
            int nOutArgCounter = 0;
            List<CodeMethodInvokeExpression> invokemethodsBuild = new List<CodeMethodInvokeExpression>();
            CodeConditionStatement condOut = null; // Root if statement for out parameters.
            CodeConditionStatement condOutIter = null; // Most nested if statement for out parameters.
            CodeStatementCollection stmtsFinishResult = new CodeStatementCollection();
            CodeTypeReference typerefParamIter = CodeBuilderCommon.typerefUnknownParameters;
            string argNameIter = arguments != null && arguments.Count > 0 ? arguments[0].Name : "UnknownParameters";

            CodeThrowExceptionStatement throwargOutPrev = codebuilder.CreateArgumentOutException(idlSignalName);

            // WAXME
            //CodeConstructor constructorArgs = new CodeConstructor();
            //constructorArgs.Attributes = MemberAttributes.Public;
            foreach (IDLSignalArgument idlSignalArg in arguments)
            {
                argNameIter = idlSignalArg.Name;

                // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument.
                //Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLMethodArgumentTypeNameBuilder(idlIntf, idlMethod, idlMethodArg);
                Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLArgumentTypeNameBuilder(idlIntf, methodName);
                ParamCodeTypeHolderMarshalBase paramtypeHolder = null;
                CodeTypeReference typerefParam = null;
                if (condOut == null)
                {
                    codebuilder.PrefixOutParams(ref condOut, ref condOutIter, idlSignalName, ref nOutArgCounter, ref throwargOutPrev);
                }

                // Handle the signal argument in the message.
                CodeConditionStatement condVarResult;
                codebuilder.MakeOutArgument(statements
                    , stmtsFinishResult
                    , idlSignalName
                    , codetypefactoryOut // Yeah I messed up the naming
                    , ref nOutArgCounter
                    , context
                    , ref throwargOutPrev
                    , idlSignalArg
                    , nameBuilder
                    , ref paramtypeHolder
                    , ref typerefParam
                    , out condVarResult
                );

                codebuilder.StoreCondIterator(ref condOut, ref condOutIter, condVarResult);

                // WAXME
                // Add a field to the <signal>Args class.
                //string argFieldName = CodeBuilderCommon.GetSignalArgFieldName(idlSignalArg.Name);
                //CodeFieldReferenceExpression fielrefdRefArgField = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), argFieldName);
                //typedeclArgs.Members.Add(new CodeMemberField(paramtypeHolder.paramtype.CodeType, argFieldName));
                //CodeMemberProperty propArgField = new CodeMemberProperty();
                //propArgField.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                //propArgField.Type = paramtypeHolder.paramtype.CodeType;
                //propArgField.Name = PropertyNameFromFieldName(argFieldName);
                //propArgField.GetStatements.Add(new CodeMethodReturnStatement(fielrefdRefArgField));
                //typedeclArgs.Members.Add(propArgField);
                //constructorArgs.Parameters.Add(new CodeParameterDeclarationExpression(paramtypeHolder.paramtype.CodeType, argFieldName));
                //// * this.<signal_arg> = <signal_arg>;
                //constructorArgs.Statements.Add(new CodeAssignStatement(fielrefdRefArgField, new CodeArgumentReferenceExpression(argFieldName)));

            } // Ends loop over arguments

            //typedeclArgs.Members.Add(constructorArgs);

            codebuilder.AssignResults(statementsTryRecv, condOut, condOutIter, stmtsFinishResult, throwargOutPrev
                , idlSignalName, ref nOutArgCounter
            );
            List<CodeStatement> statementsReponse = new List<CodeStatement>();

            // Now receive the response.
            // Create message reader.
            // * Udbus.Core.UdbusMessageReader reader = new Udbus.Core.UdbusMessageReader(msgHandleResp);
            statementsTryRecv.Insert(0, codebuilder.CreateMessageReader());
            statementsReponse.AddRange(statementsTryRecv.Cast<CodeStatement>());
            statements.Add(new CodeConditionStatement(exprResultOk, statementsReponse.ToArray()));
        }