protected virtual void WriteEntity(EdiBaseEntity ent, ref StringBuilder sb, IValidatedEntity validationScope = null)
        {
            if (ent is EdiLoop)
            {
                foreach (var child in ((EdiLoop)ent).Content)
                {
                    WriteEntity(child, ref sb);
                }
            }
            else if (ent is EdiSegment)
            {
                var seg = (EdiSegment)ent;

                _currentTranSegCount++;

                sb.Append(ent.Name);
                foreach (var el in ((EdiSegment)ent).Content)
                {
                    sb.Append($"{CurrentElementSeparator}{el.Val}");
                }
                sb.Append(CurrentSegmentSeparator);

                if (validationScope != null)
                {
                    SegmentValidator.ValidateSegment(seg, _currentTranSegCount, validationScope);
                }
            }
        }
        public static EdiSegment ProcessSegment(MapBaseEntity definition, string[] content, int rowPos, string compositeSeparator, IValidatedEntity validationScope)
        {
            MapSegment segDef = (MapSegment)definition;
            EdiSegment seg    = new EdiSegment(segDef);

            int i = 0;

            foreach (string val in content.Skip(1))
            {
                MapSimpleDataElement    elDef = null;
                MapCompositeDataElement cDef  = null;
                if (i < segDef.Content.Count)
                {
                    if (segDef.Content[i] is MapSimpleDataElement)
                    {
                        elDef = (MapSimpleDataElement)segDef.Content[i];
                    }
                    else if (segDef.Content[i] is MapCompositeDataElement)
                    {
                        cDef = (MapCompositeDataElement)segDef.Content[i];
                    }
                }

                //if cDef is null - create simple element. Even if elDef is null
                // validation will add error of unknown element later on
                if (cDef == null)
                {
                    EdiSimpleDataElement el = new EdiSimpleDataElement(elDef, val);
                    seg.Content.Add(el);
                }
                else
                {
                    EdiCompositeDataElement composite = new EdiCompositeDataElement(cDef);
                    string[] compositeContent         = val.Split(new[] { compositeSeparator }, StringSplitOptions.None);
                    ProcessComposite(composite, compositeContent);
                    seg.Content.Add(composite);
                }

                i++;
            }

            SegmentValidator.ValidateSegment(seg, rowPos, validationScope);
            return(seg);
        }