public override void GenerateMappingCode(CodeGenerationContext ctx, CodeMemberMethod method) { if (!String.IsNullOrEmpty(To)) { MappedProperty = TypeReflector.GetProperty(ctx.MappedObjectType, To); } CodeExpression segmentObj; if (MappedProperty != null) { // mappedObj.PropName = new SegmentType(); method.Statements.AddRange(GenerateSetMappedPropertyCode(ctx.MappedObject, new CodeObjectCreateExpression(_segmentType))); segmentObj = GetMappedProperty(ctx.MappedObject); } else { // this._segmentField = new SegmentType(); segmentObj = ctx.Builder.AddNewField(SegmentType); method.Statements.Add(new CodeAssignStatement(segmentObj, new CodeObjectCreateExpression(_segmentType))); } CodeGenerationContext segmentCtx = ctx.Clone(); segmentCtx.MappedObject = segmentObj; segmentCtx.MappedObjectType = _segmentType; method.Statements.AddRange(ctx.Builder.NewElementsMappingCode(segmentCtx, Nodes)); }
public override void GenerateMappingCode(CodeGenerationContext ctx, CodeMemberMethod method) { if (!String.IsNullOrEmpty(To)) { MappedProperty = TypeReflector.GetProperty(ctx.MappedObjectType, To); } // byte[] bytes = reader.ReadBytes(length); method.Statements.Add(new CodeVariableDeclarationStatement(typeof(byte[]), "bytes", new CodeMethodInvokeExpression(ctx.DataReader, "ReadBytes", new CodePrimitiveExpression(Length)))); if (MappedProperty != null) { // MemoryStream stream2 = new MemoryStream(bytes); CodeVariableReferenceExpression bytes = new CodeVariableReferenceExpression("bytes"); method.Statements.Add(new CodeVariableDeclarationStatement( typeof(MemoryStream), "stream2", new CodeObjectCreateExpression(typeof(MemoryStream), bytes))); CodeVariableReferenceExpression stream2 = new CodeVariableReferenceExpression("stream2"); // BinaryReader newReader = new BinarryReader(stream2); method.Statements.Add(new CodeVariableDeclarationStatement( typeof(BinaryReader), "reader2", new CodeObjectCreateExpression(typeof(BinaryReader), stream2))); CodeVariableReferenceExpression reader2 = new CodeVariableReferenceExpression("reader2"); //Type value = ? method.Statements.Add(new CodeVariableDeclarationStatement( MappedValueType, "value", GetPropertyValueExpression(MappedValueType, reader2))); CodeVariableReferenceExpression value = new CodeVariableReferenceExpression("value"); // add operations code foreach (IOperation op in Operations) { method.Statements.AddRange(op.BuildOperation(ctx, this, value)); } method.Statements.AddRange(GenerateSetMappedPropertyCode(ctx.MappedObject, value)); // newReader.Dispose(); method.Statements.Add(new CodeMethodInvokeExpression(reader2, "Close")); // newStream.Dispose(); method.Statements.Add(new CodeMethodInvokeExpression(stream2, "Close")); } }
public override void GenerateMappingCode(CodeGenerationContext ctx, CodeMemberMethod method) { if (!String.IsNullOrEmpty(To)) { MappedProperty = TypeReflector.GetProperty(ctx.MappedObjectType, To); } if (MappedProperty != null) { if (MapNotBoolProperty) { // type value = bitReader.ReadBits(length); method.Statements.Add(new CodeVariableDeclarationStatement(MappedValueType, "value", new CodeMethodInvokeExpression(ctx.DataReader, "ReadBits", new CodePrimitiveExpression(Length)))); } else { method.Statements.Add( new CodeVariableDeclarationStatement(MappedValueType, "value", new CodeBinaryOperatorExpression( new CodeMethodInvokeExpression(ctx.DataReader, "ReadBits", new CodePrimitiveExpression(Length)), CodeBinaryOperatorType.GreaterThan, new CodePrimitiveExpression(0)))); } // add operations code CodeVariableReferenceExpression value = new CodeVariableReferenceExpression("value"); foreach (IOperation op in Operations) { method.Statements.AddRange(op.BuildOperation(ctx, this, value)); } method.Statements.AddRange(GenerateSetMappedPropertyCode(ctx.MappedObject, value)); } else { // just read method.Statements.Add( new CodeMethodInvokeExpression(ctx.DataReader, "ReadBits", new CodePrimitiveExpression(Length))); } }