/// <summary> /// Initializes a new instance of the <see cref="X12Document"/> class /// from the specified X12 parser. /// </summary> /// <param name="parser">The X12 parser.</param> /// <param name="maxTransactionCount">Maximum number of transactions to load.</param> public X12Document(X12SegmentParser parser, int maxTransactionCount = int.MaxValue) : this() { if (parser == null) throw new ArgumentNullException("parser"); Load(parser, maxTransactionCount); }
/// <summary> /// Loads the document from the specified X12 parser. /// </summary> /// <param name="parser">The X12 parser.</param> /// <param name="maxTransactionCount">Maximum number of transactions to load.</param> /// <returns> /// Reference to this document (for chaining commands). /// </returns> /// <exception cref="System.ArgumentNullException">parser</exception> public X12Document Load(X12SegmentParser parser, int maxTransactionCount = int.MaxValue) { if (parser == null) throw new ArgumentNullException("parser"); // Prime empty segment container with cached values from the reader if needed if (Segments.Count == 0) Add(Interchange = parser.Interchange); if (Segments.Count == 1 && parser.FunctionalGroup != null) Add(parser.FunctionalGroup); var counter = 0; while (counter++ < maxTransactionCount) { var transaction = parser.ParseNextTransaction().ToList(); if (transaction.Count > 0) Add(transaction); else break; } return this; }