public override System.CodeDom.CodeMemberMethod GetSerializerMethod()
        {
            CodeMemberMethod method = base.GetSerializerMethod();

            IMemberReaderWriter entry = BaseEntry as IMemberReaderWriter;

            List <CodeStatement> loopStatements = new List <CodeStatement>();

            loopStatements.Add(CodeGen.GetStatement(
                                   entry.GetWriterExpression(CodeGen.GetWriter(), new CodeIndexerExpression(CodeGen.GetObject(), CodeGen.GetVariable("i")))));

            method.Statements.Add(CodeGen.GetForLoop("i", 0,
                                                     CodeGen.GetProperty(CodeGen.GetObject(), "Length"), 1, loopStatements.ToArray()));

            return(method);
        }
Пример #2
0
        public override System.CodeDom.CodeMemberMethod GetDeserializerMethod()
        {
            CodeMemberMethod    method = base.GetDeserializerMethod();
            IMemberReaderWriter entry  = BaseEntry as IMemberReaderWriter;

            if (_isByteLength)
            {
                CodeTypeReference listType = CodeGen.CreateGenericType(typeof(List <>), BaseEntry.GetTypeReference());
                method.Statements.Add(CodeGen.MakeVariable(listType, "ret",
                                                           CodeGen.CreateObject(listType)));

                method.Statements.Add(CodeGen.GetAssign(CodeGen.GetReader(),
                                                        CodeGen.CallMethod(CodeGen.GetThis(), "GBR", CodeGen.GetReader(), CodeGen.GetPrimitive(_lengthExpression))));

                List <CodeStatement> loopStatements = new List <CodeStatement>();

                CodeExpression expr = CodeGen.CallMethod(CodeGen.GetVariable("ret"), "Add", entry.GetReaderExpression(CodeGen.GetReader()));

                method.Statements.Add(CodeGen.GetTryCatch(new CodeStatement[] { CodeGen.GetInfLoop(new CodeExpressionStatement(expr)) }, typeof(EndOfStreamException)));

                method.Statements.Add(CodeGen.GetReturn(CodeGen.CallMethod(CodeGen.GetVariable("ret"), "ToArray")));
            }
            else
            {
                method.Statements.Add(CodeGen.MakeVariable(GetTypeReference(), "ret",
                                                           CodeGen.CreateArray(GetTypeReference(), CodeGen.GetLength(Length))));

                List <CodeStatement> loopStatements = new List <CodeStatement>();

                loopStatements.Add(CodeGen.GetAssign(
                                       CodeGen.GetIndex(
                                           CodeGen.GetVariable("ret"), CodeGen.GetVariable("i")
                                           ),
                                       entry.GetReaderExpression(CodeGen.GetReader()))
                                   );

                method.Statements.Add(CodeGen.GetForLoop("i", 0, CodeGen.GetProperty(CodeGen.GetVariable("ret"), "Length"), 1, loopStatements.ToArray()));

                method.Statements.Add(CodeGen.GetReturn(CodeGen.GetVariable("ret")));
            }

            return(method);
        }
Пример #3
0
        public override System.CodeDom.CodeMemberMethod GetSerializerMethod()
        {
            CodeMemberMethod method = base.GetSerializerMethod();

            // No point doing anything if there is no length to write
            if (_reference.IsValid())
            {
                IMemberReaderWriter entry = BaseEntry as IMemberReaderWriter;

                List <CodeStatement> loopStatements = new List <CodeStatement>();

                loopStatements.Add(CodeGen.GetStatement(entry.GetWriterExpression(CodeGen.GetWriter(), CodeGen.GetIndex(CodeGen.GetObject(),
                                                                                                                        CodeGen.GetVariable("i")))));

                method.Statements.Add(CodeGen.GetForLoop("i", 0, CodeGen.GetProperty(CodeGen.GetObject(), "Length"),
                                                         1, loopStatements.ToArray()));
            }

            return(method);
        }
Пример #4
0
        public override System.CodeDom.CodeMemberMethod GetPreSerializeMethod()
        {
            CodeMemberMethod method = base.GetPreSerializeMethod();

            if (_reference.IsValid())
            {
                CodeExpression right;

                if (_isByteLength)
                {
                    // Should really save this out and reuse when it comes to actually writing the data, seems a waste
                    method.Statements.Add(CodeGen.MakeVariable(typeof(DataWriter), "writer", CodeGen.CreateObject(typeof(DataWriter))));

                    IMemberReaderWriter entry = BaseEntry as IMemberReaderWriter;

                    List <CodeStatement> loopStatements = new List <CodeStatement>();

                    loopStatements.Add(CodeGen.GetStatement(entry.GetWriterExpression(CodeGen.GetWriter(), CodeGen.GetIndex(CodeGen.GetThisField(Name),
                                                                                                                            CodeGen.GetVariable("i")))));

                    method.Statements.Add(CodeGen.GetForLoop("i", 0, CodeGen.GetProperty(CodeGen.GetThisField(Name), "Length"),
                                                             1, loopStatements.ToArray()));

                    right = CodeGen.GetProperty(CodeGen.GetVariable("writer"), "BytesWritten");
                }
                else
                {
                    right = CodeGen.GetProperty(CodeGen.GetThisField(Name), "Length");
                }

                if (_adjustment != 0)
                {
                    right = CodeGen.GetOperator(right, CodeBinaryOperatorType.Subtract, CodeGen.GetPrimitive(_adjustment));
                }

                method.Statements.Add(CodeGen.GetAssign(CodeGen.GetField(CodeGen.GetThis(),
                                                                         _reference.GetNames()), CodeGen.GetCast(_reference.GetTargetMember().GetTypeReference(), right)));
            }

            return(method);
        }
Пример #5
0
        public override System.CodeDom.CodeMemberMethod GetDeserializerMethod()
        {
            CodeMemberMethod    method = base.GetDeserializerMethod();
            IMemberReaderWriter entry  = BaseEntry as IMemberReaderWriter;

            if (_reference.IsValid())
            {
                CodeTypeReference    listType       = CodeGen.CreateGenericType(typeof(List <>), BaseEntry.GetTypeReference());
                List <CodeStatement> loopStatements = new List <CodeStatement>();

                method.Statements.Add(CodeGen.MakeVariable(listType, "ret", CodeGen.CreateObject(listType)));

                method.Statements.Add(CodeGen.MakeVariable(typeof(int), "length", GetLength()));

                loopStatements.Add(CodeGen.GetStatement(CodeGen.CallMethod(CodeGen.GetVariable("ret"), "Add", entry.GetReaderExpression(CodeGen.GetReader()))));

                if (_isByteLength)
                {
                    // Reassign reader to just the sub data
                    method.Statements.Add(CodeGen.MakeVariable(typeof(DataReader), "reader", CodeGen.CreateObject(typeof(DataReader),
                                                                                                                  CodeGen.CallMethod(CodeGen.GetArgument("reader"), "ReadBytes", GetLength()))));

                    method.Statements.Add(CodeGen.GetTryCatch(new CodeStatement[] { CodeGen.GetInfLoop(loopStatements.ToArray()) }, typeof(EndOfStreamException)));

                    method.Statements.Add(CodeGen.CallMethod(CodeGen.GetArgument("reader"), "Flush"));
                }
                else
                {
                    method.Statements.Add(CodeGen.GetForLoop("i", 0, CodeGen.GetVariable("length"), 1, loopStatements.ToArray()));
                }

                method.Statements.Add(CodeGen.GetReturn(CodeGen.CallMethod(CodeGen.GetVariable("ret"), "ToArray")));
            }
            else
            {
                method.Statements.Add(CodeGen.GetReturn(CodeGen.CreateArray(GetTypeReference(), 0)));
            }

            return(method);
        }