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); }