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

            if (_reference.IsValid())
            {
                CodeExpression right = CodeGen.GetProperty(CodeGen.GetThisField(Name), "Length");

                if (_isByteLength)
                {
                    PrimitiveMemberEntry entry    = BaseEntry as PrimitiveMemberEntry;
                    BitFieldMemberEntry  bitField = entry as BitFieldMemberEntry;

                    if (bitField != null)
                    {
                        right = CodeGen.CallMethod(CodeGen.GetThis(), "CLBits", right, CodeGen.GetPrimitive(bitField.Bits));
                    }
                    else
                    {
                        right = CodeGen.GetOperator(CodeGen.GetPrimitive(entry.GetSize()), CodeBinaryOperatorType.Multiply, right);
                    }
                }

                EvalExpression lengthWrite = LengthWriteExpression;

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

                if (_reference.GetTargetMember().BaseType is StringParserType)
                {
                    right = CodeGen.CallMethod(right, "ToString");
                }
                else
                {
                    right = CodeGen.GetCast(_reference.GetTargetMember().GetTypeReference(), right);
                }

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

            return(method);
        }
        public override CodeMemberMethod GetPreSerializeMethod()
        {
            CodeMemberMethod method = base.GetPreSerializeMethod();

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

                if (_isByteLength)
                {
                    right = CodeGen.CallMethod(CodeGen.GetThis(), "SBL", CodeGen.GetThisField(Name), CodeGen.GetEnum(StringEncoding));
                }
                else
                {
                    right = CodeGen.GetProperty(CodeGen.GetThisField(Name), "Length");
                }

                EvalExpression lengthWrite = LengthWriteExpression;

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

                if (_reference.GetTargetMember().BaseType is StringParserType)
                {
                    right = CodeGen.CallMethod(right, "ToString");
                }
                else
                {
                    right = CodeGen.GetCast(_reference.GetTargetMember().GetTypeReference(), right);
                }

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

            return(method);
        }
Beispiel #3
0
        private CodeExpression GetLength()
        {
            Type refType = ((BuiltinParserType)_reference.GetTargetMember().BaseType).DataType;

            CodeExpression ret = CodeGen.GetField(CodeGen.GetThis(), _reference.GetNames());

            if (refType != typeof(int))
            {
                ret = CodeGen.CallMethod(CodeGen.GetThis(), "CL", ret);
            }

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

            return(ret);
        }