/// <summary>
 /// Initializes a new instance of the <see cref="X12TransactionSet" /> class.
 /// </summary>
 /// <param name="segment">The segment.</param>
 /// <param name="delimiterSet">The delimiter set.</param>
 /// <param name="parentFunctionalGroup">The parent functional group.</param>
 public X12TransactionSet(string segment, X12DelimiterSet delimiterSet, X12FunctionalGroup parentFunctionalGroup)
     : base(segment, delimiterSet, null, parentFunctionalGroup)
 {
     ParentFunctionalGroup = parentFunctionalGroup;
 }
        private X12Segment CreateSegment(string segment)
        {
            var id = segment.Substring(0, segment.IndexOf(_delimiterSet.ElementSeparator));
            _indexCounter++;
            Counter++;

            switch (id)
            {
                case "ISA": // Interchange Start
                    if (Interchange != null)
                        ParseError(segment, "Only one ISA segment is allowed.");
                    _delimiterSet = new X12DelimiterSet(segment.ToCharArray());
                    return (_parentSegment = Interchange = new X12Interchange(segment, _delimiterSet));

                case "GS": // Function Group Start
                    if (Interchange == null)
                        ParseError(segment, "Segment '{0}' cannot occur before an ISA segment.", segment);
                    return (_parentSegment = FunctionalGroup = new X12FunctionalGroup(segment, _delimiterSet, Interchange));

                case "ST": // Start Transaction Set
                    if (FunctionalGroup == null)
                        ParseError(segment, "segment '{0}' cannot occur without a preceding GS segment.", segment);
                    TransactionSet = new X12TransactionSet(segment, _delimiterSet, FunctionalGroup);
                    if (FunctionalGroup != null) TransactionSet.Specification =
                        SpecificationLocator.FindTransactionSpec(TransactionSet.IdentifierCode, FunctionalGroup.VersionIdentifierCode);
                    _indexCounter = 0;
                    return _parentSegment = TransactionSet;

                case "SE": // End Transaction Set
                    if (TransactionSet == null)
                        ParseError(segment, "Segment '{0}' does not have a matching ST segment preceding it.", segment);
                    _parentSegment = FunctionalGroup;
                    return new X12TransactionSetTrailer(segment, _delimiterSet, TransactionSet);

                case "GE": // End Functional Specification
                    if (FunctionalGroup == null)
                        ParseError(segment, "Segment '{0}' does not have a matching GS segment precending it.", segment);
                    _parentSegment = Interchange;
                    return new X12FunctionalGroupTrailer(segment, _delimiterSet, FunctionalGroup);

                case "ISE": // End Interchange
                    if (Interchange == null)
                        ParseError(segment, "Segment '{0}' does not have a matching ISA segment preceding it.", segment);
                    _parentSegment = null;
                    return new X12InterchangeTrailer(segment, _delimiterSet, Interchange);

                default:
                    var spec = (_loadSegmentSpec && FunctionalGroup != null)
                                    ? SpecificationLocator.GetSegmentSpec(FunctionalGroup.VersionIdentifierCode, id)
                                    : null;
                    return new X12Segment(segment, _delimiterSet, spec, _parentSegment);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="X12FunctionalGroupTrailer" /> class.
 /// </summary>
 /// <param name="gsSegment">The gs segment.</param>
 /// <param name="delimiterSet">The delimiter set.</param>
 /// <param name="parentFunctionalGroup">The parent functional group.</param>
 public X12FunctionalGroupTrailer(string gsSegment, X12DelimiterSet delimiterSet, X12FunctionalGroup parentFunctionalGroup)
     : base(gsSegment, delimiterSet)
 {
     ParentFunctionalGroup = parentFunctionalGroup;
 }