internal override void ToX12String(bool addWhitespace, System.IO.StreamWriter writer) { if (writer == null) { throw new ArgumentNullException("writer", "StreamWriter cannot be null"); } writer.Write(base.ToX12String(addWhitespace)); foreach (var segment in this.Segments.Where(seg => !TrailerSegmentIds.Contains(seg.SegmentId))) { if (addWhitespace) { writer.Write(segment.ToX12String(addWhitespace).Replace("\r\n", "\r\n ")); } else { writer.Write(segment.ToX12String(addWhitespace)); } } if (addWhitespace) { // Not sure how to handle the new line strips here. Investigate... writer.Write(SerializeBodyToX12(addWhitespace).Replace("\r\n", "\r\n ")); } else { SerializeBodyToX12(addWhitespace, writer); } foreach (var segment in this.Segments.Where(seg => TrailerSegmentIds.Contains(seg.SegmentId))) { if (addWhitespace) { writer.Write(segment.ToX12String(addWhitespace).Replace("\r\n", "\r\n ")); } else { writer.Write(segment.ToX12String(addWhitespace)); } } foreach (var segment in this.TrailerSegments) { string[] wrapperSegments = new string[] { "SE", "GE", "IEA" }; if (addWhitespace && !wrapperSegments.Contains(segment.SegmentId)) { writer.Write(segment.ToX12String(addWhitespace).Replace("\r\n", "\r\n ")); } else { writer.Write(segment.ToX12String(addWhitespace)); } } }
internal override string ToX12String(bool addWhitespace) { StringBuilder sb = new StringBuilder(base.ToX12String(addWhitespace)); foreach (var segment in this.Segments.Where(seg => !TrailerSegmentIds.Contains(seg.SegmentId))) { if (addWhitespace) { sb.Append(segment.ToX12String(addWhitespace).Replace("\r\n", "\r\n ")); } else { sb.Append(segment.ToX12String(addWhitespace)); } } if (addWhitespace) { sb.Append(SerializeBodyToX12(addWhitespace).Replace("\r\n", "\r\n ")); } else { sb.Append(SerializeBodyToX12(addWhitespace)); } foreach (var segment in this.Segments.Where(seg => TrailerSegmentIds.Contains(seg.SegmentId))) { if (addWhitespace) { sb.Append(segment.ToX12String(addWhitespace).Replace("\r\n", "\r\n ")); } else { sb.Append(segment.ToX12String(addWhitespace)); } } foreach (var segment in this.TrailerSegments) { string[] wrapperSegments = new string[] { "SE", "GE", "IEA" }; if (addWhitespace && !wrapperSegments.Contains(segment.SegmentId)) { sb.Append(segment.ToX12String(addWhitespace).Replace("\r\n", "\r\n ")); } else { sb.Append(segment.ToX12String(addWhitespace)); } } return(sb.ToString()); }