private CodeExpression GetLength() { CodeExpression ret = CodeGen.GetCast(typeof(int), CodeGen.GetField(CodeGen.GetThis(), _reference.GetNames())); if (_adjustment != 0) { ret = CodeGen.GetOperator(ret, CodeBinaryOperatorType.Add, CodeGen.GetPrimitive(_adjustment)); } return(ret); }
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); }
public CodeExpression GetWriterExpression(CodeExpression writer, CodeExpression obj) { return(_primitiveEntry.GetWriterExpression(writer, CodeGen.GetCast(_primitiveEntry.GetCastType(), CodeGen.GetCast(typeof(long), obj)) )); }
public CodeExpression GetReaderExpression(CodeExpression reader) { return(CodeGen.GetCast(EnumType.Name, CodeGen.GetCast(typeof(long), _primitiveEntry.GetReaderExpression(reader)))); }
public CodeExpression GetWriterExpression(CodeExpression writer, CodeExpression obj) { return(_primitiveEntry.GetWriterExpression(writer, CodeGen.GetCast(_primitiveEntry.GetCastType(), CodeGen.CallMethod(typeof(ParserUtils), "GetBooleanValue", _primitiveEntry.GetDataType(), obj, CodeGen.GetPrimitive(_trueValue), CodeGen.GetPrimitive(_falseValue))))); }
public CodeExpression GetReaderExpression(CodeExpression reader) { return(CodeGen.GetOperator(CodeGen.GetPrimitive(_falseValue), CodeBinaryOperatorType.IdentityInequality, CodeGen.GetCast(_primitiveEntry.GetDataType(), _primitiveEntry.GetReaderExpression(reader)))); }
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); }