public override System.CodeDom.CodeMemberMethod GetDeserializerMethod() { CodeMemberMethod method = base.GetDeserializerMethod(); CodeTypeReference listType = CodeGen.CreateGenericType(typeof(List <>), BaseEntry.GetTypeReference()); method.Statements.Add(CodeGen.MakeVariable(listType, "ret", CodeGen.CreateObject(listType))); if (TrailingLength.IsValid) { int length; // If not a primitive expression or the length is not 0 if (!TrailingLength.ParseInt(out length) || (length != 0)) { method.Statements.Add(CodeGen.GetAssign(CodeGen.GetReader(), CodeGen.CreateObject(typeof(DataReader), CodeGen.CallMethod(CodeGen.GetReader(), "ReadToEndTrail", CodeGen.GetLength(TrailingLength))))); } } List <CodeStatement> loopStatements = new List <CodeStatement>(); loopStatements.Add(CodeGen.GetStatement(CodeGen.CallMethod(CodeGen.GetVariable("ret"), "Add", _memberEntry.GetReaderExpression(CodeGen.GetReader())))); method.Statements.Add( CodeGen.GetTryCatch(new CodeStatement[] { CodeGen.GetInfLoop(loopStatements.ToArray()) }, typeof(EndOfStreamException))); method.Statements.Add(CodeGen.GetReturn(CodeGen.CallMethod(CodeGen.GetVariable("ret"), "ToArray"))); return(method); }
public CodeExpression GetReaderExpression(CodeExpression reader) { CodeExpression ret = null; IMemberReaderWriter entry = BaseEntry as IMemberReaderWriter; if (_reference.IsValid()) { string name = _isByteLength ? "SAB" : "SA"; List <CodeExpression> parameters = new List <CodeExpression>(); parameters.Add(reader); EvalExpression lengthRead = LengthReadExpression; parameters.Add(CodeGen.GetField(CodeGen.GetThis(), _reference.GetNames())); if (lengthRead.IsValid) { parameters.Add(CodeGen.GetPrimitive(lengthRead.Expression)); } else { parameters.Add(CodeGen.GetPrimitive(_adjustment)); } ret = CodeGen.CallMethod(CodeGen.GetThis(), name, BaseEntry.GetTypeReference(), parameters.ToArray()); } else { ret = CodeGen.CreateArray(GetTypeReference(), 0); } return(ret); }
public System.CodeDom.CodeExpression GetReaderExpression(CodeExpression reader) { CodeExpression ret = OnlyCalculated ? reader : _memberEntry.GetReaderExpression(reader); ret = CodeGen.GetCalc(ReadExpression, BaseEntry.GetTypeReference(), ret); return(ret); }
public System.CodeDom.CodeExpression GetWriterExpression(CodeExpression writer, CodeExpression obj) { if (OnlyCalculated) { return(CodeGen.GetResolve(WriteExpression, obj, writer)); } else { obj = CodeGen.GetCalc(WriteExpression, BaseEntry.GetTypeReference(), CodeGen.GetRef(obj)); return(_memberEntry.GetWriterExpression(writer, obj)); } }
public CodeExpression GetReaderExpression(CodeExpression reader) { if (_isByteLength) { return(CodeGen.CallMethod(CodeGen.GetThis(), "FixBPA", BaseEntry.GetTypeReference(), reader, CodeGen.GetLength(Length), _intEntry.GetEndian())); } else { return(CodeGen.CallMethod(CodeGen.GetThis(), "FixPA", BaseEntry.GetTypeReference(), reader, CodeGen.GetLength(Length), _intEntry.GetEndian())); } }
public CodeExpression GetReaderExpression(CodeExpression reader) { CodeExpression ret; PrimitiveMemberEntry entry = BaseEntry as PrimitiveMemberEntry; if (_reference.IsValid()) { CodeExpression lengthExpression; EvalExpression lengthRead = LengthReadExpression; if (lengthRead.IsValid) { lengthExpression = CodeGen.CallMethod(CodeGen.GetThis(), "CL", CodeGen.GetField(CodeGen.GetThis(), _reference.GetNames()), CodeGen.GetPrimitive(lengthRead.Expression)); } else { Type refType = ((BuiltinParserType)_reference.GetTargetMember().BaseType).DataType; lengthExpression = CodeGen.GetField(CodeGen.GetThis(), _reference.GetNames()); if (refType != typeof(int)) { lengthExpression = CodeGen.CallMethod(CodeGen.GetThis(), "CL", lengthExpression); } if (_adjustment != 0) { lengthExpression = CodeGen.GetOperator(lengthExpression, CodeBinaryOperatorType.Add, CodeGen.GetPrimitive(_adjustment)); } } if (_isByteLength) { ret = CodeGen.CallMethod(CodeGen.GetThis(), "FixBPA", BaseEntry.GetTypeReference(), reader, lengthExpression, ((IntegerPrimitiveMemberEntry)BaseEntry).GetEndian()); } else { ret = CodeGen.CallMethod(CodeGen.GetThis(), "FixPA", BaseEntry.GetTypeReference(), reader, lengthExpression, ((IntegerPrimitiveMemberEntry)BaseEntry).GetEndian()); } } else { ret = CodeGen.CreateArray(BaseEntry.GetTypeReference(), 0); } return(ret); }
public override System.CodeDom.CodeMemberMethod GetDeserializerMethod() { CodeMemberMethod method = base.GetDeserializerMethod(); CodeTypeReference listType = CodeGen.CreateGenericType(typeof(List <>), BaseEntry.GetTypeReference()); method.Statements.Add(CodeGen.MakeVariable(listType, "ret", CodeGen.CreateObject(listType))); method.Statements.Add(CodeGen.MakeVariable(typeof(int), "i", CodeGen.GetPrimitive(0))); List <CodeStatement> loopStatements = new List <CodeStatement>(); loopStatements.Add(CodeGen.MakeVariable(BaseEntry.GetTypeReference(), "o", _memberEntry.GetReaderExpression(CodeGen.GetReader()))); loopStatements.Add(CodeGen.GetStatement(CodeGen.CallMethod(CodeGen.GetVariable("ret"), "Add", CodeGen.GetVariable("o")))); if (TermExpression.IsValid) { CodeStatement[] ret = new CodeStatement[] { CodeGen.GetReturn(CodeGen.CallMethod(CodeGen.GetVariable("ret"), "ToArray")) }; loopStatements.Add(CodeGen.GetIf(CodeGen.GetCheck(TermExpression, CodeGen.GetVariable("o"), CodeGen.GetVariable("i")), ret)); loopStatements.Add(CodeGen.GetIncrement(CodeGen.GetVariable("i"), 1)); } if (!_required) { method.Statements.Add( CodeGen.GetTryCatch(new CodeStatement[] { CodeGen.GetInfLoop(loopStatements.ToArray()) }, typeof(EndOfStreamException))); method.Statements.Add(CodeGen.GetReturn(CodeGen.CallMethod(CodeGen.GetVariable("ret"), "ToArray"))); } else { method.Statements.Add(CodeGen.GetInfLoop(loopStatements.ToArray())); } return(method); }
public override System.CodeDom.CodeTypeReference GetTypeReference() { return(BaseEntry.GetTypeReference()); }
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); }
/// <summary> /// Get type reference /// </summary> /// <returns>The type reference (base type array)</returns> public override CodeTypeReference GetTypeReference() { return(new CodeTypeReference(BaseEntry.GetTypeReference(), 1)); }
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); }