Exemplo n.º 1
0
        internal static void Encode(HL7Separators seps, System.Text.StringBuilder sb, Type type, object value)
        {
            if (value == null)
            {
                // Do nothing
            }
            else if (type.IsArray)
            {
                foreach (object element in value as Array)
                {
                    Encode(seps, sb, type.GetElementType(), element);
                    sb.Append(seps.FieldRepeatSeparator);
                }

                // Remove the last field repeat separator.
                sb.Remove(sb.Length - 1, 1);
            }
            else if (type.Equals(typeof(string)))
            {
                sb.Append(seps.Encode(value as string));
            }
            else
            {
                foreach (FieldInfo component in type.GetFields())
                {
                    HL7Component.Encode(seps, sb, component.FieldType, component.GetValue(value));
                    sb.Append(seps.ComponentSeparator);
                }

                // Remove the last component separator.
                sb.Remove(sb.Length - 1, 1);
            }
        }
        internal static void Encode(HL7Separators seps, System.Text.StringBuilder sb, Type type, object value)
        {
            // A component is either empty, a string or an HL7 data structure containing subcomponents.
            if (value == null)
            {
                // Do nothing
            }
            else if (value is string)
            {
                sb.Append(seps.Encode(value as string));
            }
            else
            {
                foreach (FieldInfo subcomponent in type.GetFields())
                {
                    // A subcomponent is always a string
                    sb.Append(seps.Encode(subcomponent.GetValue(value) as string));
                    sb.Append(seps.SubcomponentSeparator);
                }

                // Remove the extraneous subcomponent separator
                sb.Remove(sb.Length - 1, 1);
            }
        }