Example #1
0
        public void Format(FormatContext context, TSegment entity)
        {
            var length = 0;

            var entityContext  = context.CreateEntityContext(entity);
            var segmentContext = entityContext.SetLevel(FormatLevel.Segment);

            var elementSeparator = segmentContext.Settings.ElementSeparator;

            for (var i = 0; i < _formatters.Length; i++)
            {
                if (i > 0)
                {
                    context.Append(elementSeparator);
                }

                var position = context.Position;

                _formatters[i].Format(entityContext.CreateEntityContext(entity));

                if (position < context.Position)
                {
                    length = context.Position;
                }
            }

            if (length == 0)
            {
                context.Clear();
            }
            else
            {
                context.Trim(length);
            }
        }
Example #2
0
        public void Format(FormatContext context, TSegment entity)
        {
            int    length = 0;
            string tag    = entity.SegmentId.Value;

            var segmentContext = context.CreateEntityContext(entity);
            var formatContext  = segmentContext.SetLevel(FormatLevel.Segment);

            var fieldSeparator = formatContext.Settings.FieldSeparator;

            for (int i = 0; i < _formatters.Length; i++)
            {
                if (i > 0)
                {
                    context.Append(fieldSeparator);
                }

                if (i == 1 && tag == "MSH")
                {
                    context.Append(formatContext.Settings.ComponentSeparator);
                    context.Append(formatContext.Settings.RepetitionSeparator);
                    context.Append(formatContext.Settings.EscapeCharacter);
                    context.Append(formatContext.Settings.SubComponentSeparator);
                    length = context.Position;
                    continue;
                }

                int position = context.Position;

                _formatters[i].Format(segmentContext.CreateEntityContext(entity));

                if (position < context.Position)
                {
                    length = context.Position;
                }
            }

            if (length == 0)
            {
                context.Clear();
            }
            else
            {
                context.Trim(length);
            }
        }
Example #3
0
        public void Format(FormatContext context, TComponent entity)
        {
            int length = 0;

            var componentContext = context.CreateEntityContext(entity);

            var formatContext = componentContext.SetLevel(x => x == FormatLevel.Component ? FormatLevel.SubComponent : FormatLevel.Component);

            var separator = formatContext.Level == FormatLevel.Component ? _settings.ComponentSeparator : _settings.SubComponentSeparator;

            for (int i = 0; i < _formatters.Length; i++)
            {
                if (i > 0)
                {
                    context.Append(separator);
                }

                int position = context.Position;

                _formatters[i].Format(componentContext.CreateEntityContext(entity));

                if (position < context.Position)
                {
                    length = context.Position;
                }
            }

            if (length == 0)
            {
                context.Clear();
            }
            else
            {
                context.Trim(length);
            }
        }