예제 #1
0
        /// <summary>
        /// Gets or sets the value of the component element at the specified position.
        /// </summary>
        /// <param name="position">The position of the component element, starting at 1.</param>
        /// <returns>A string containing the value of the component element.</returns>
        public string this[int position]
        {
            get
            {
                int index = position - 1;
                if (Components.Count <= index || Components[index] == null)
                {
                    return(null);
                }
                return(Components[index].Value);
            }

            set
            {
                int index = position - 1;
                if (!string.IsNullOrEmpty(value))
                {
                    while (Components.Count <= index)
                    {
                        Components.Add(null);
                    }
                    Components[index] = new EdiComponent(value);
                }
                else if (Components.Count > index)
                {
                    Components[index] = null;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Gets or sets the value of the component element at the specified position.
        /// </summary>
        /// <param name="position">The position of the component element, starting at 1.</param>
        /// <returns>A string containing the value of the component element.</returns>
        public string this[int position]
        {
            get
            {
                int index = position - 1;
                if (Components.Count <= index || Components[index] == null)
                    return null;
                return Components[index].Value;
            }

            set
            {
                int index = position - 1;
                if (!string.IsNullOrEmpty(value))
                {
                    while (Components.Count <= index)
                        Components.Add(null);
                    Components[index] = new EdiComponent(value);
                }
                else if (Components.Count > index)
                    Components[index] = null;
            }
        }
예제 #3
0
 private XElement MapComponent(EdiComponent component, Component mapping, string defaultComponentId)
 {
     if (mapping != null)
     {
         var    xml = new XElement(mapping.Id);
         string mappedValue;
         if (mapping.Type == null || !MapValue(component, mapping.Type, out mappedValue))
         {
             xml.Value = component.Value;
         }
         else
         {
             xml.SetAttributeValue("type", mapping.Type);
             xml.Value = mappedValue;
         }
         if (mapping.Options.Contains(component.Value))
         {
             string definition = mapping.Options[component.Value];
             xml.SetAttributeValue("definition", definition);
         }
         return(xml);
     }
     return(new XElement(defaultComponentId, component.Value));
 }
예제 #4
0
 public bool IsMatch(EdiComponent component)
 {
     return !_restrict || (component != null && Options.Contains(component.Value));
 }
예제 #5
0
 private XElement MapComponent(EdiComponent component, Component mapping, string defaultComponentId)
 {
     if (mapping != null)
     {
         var xml = new XElement(mapping.Id);
         string mappedValue;
         if (mapping.Type == null || !MapValue(component, mapping.Type, out mappedValue))
             xml.Value = component.Value;
         else
         {
             xml.SetAttributeValue("type", mapping.Type);
             xml.Value = mappedValue;
         }
         if (mapping.Options.Contains(component.Value))
         {
             string definition = mapping.Options[component.Value];
             xml.SetAttributeValue("definition", definition);
         }
         return xml;
     }
     return new XElement(defaultComponentId, component.Value);
 }
예제 #6
0
 public bool IsMatch(EdiComponent component)
 {
     return(!_restrict || (component != null && Options.Contains(component.Value)));
 }
예제 #7
0
        private IEnumerable <XElement> MapElement(EdiElement element, Element mapping, string defaultElementId)
        {
            var repetitions = new List <XElement>();

            foreach (EdiRepetition repetition in element.Repetitions)
            {
                var xml = new XElement(mapping != null ? mapping.Id : defaultElementId);
                if (repetition.Components.Count == 1)
                {
                    if (mapping != null)
                    {
                        if (mapping.Components.Count == 0)
                        {
                            string mappedValue;
                            if (mapping.Type == null || !MapValue(repetition, mapping.Type, out mappedValue))
                            {
                                xml.Value = repetition.Value;
                            }
                            else
                            {
                                xml.SetAttributeValue("type", mapping.Type);
                                xml.Value = mappedValue;
                            }
                            if (mapping.Options.Contains(repetition.Value))
                            {
                                string definition = mapping.Options[repetition.Value];
                                if (definition != null && definition.Trim() != string.Empty)
                                {
                                    xml.SetAttributeValue("definition", definition);
                                }
                            }
                        }
                        else
                        {
                            xml.Add(MapComponent(repetition.Components[0], mapping.Components[0], mapping.Id + "01"));
                        }
                    }
                    else
                    {
                        xml.Value = repetition.Value;
                    }
                }
                else
                {
                    for (int i = 0; i < repetition.Components.Count; i++)
                    {
                        EdiComponent component = repetition.Components[i];
                        if (component == null)
                        {
                            continue;
                        }
                        Component componentMapping = null;
                        string    elementId;
                        if (mapping != null)
                        {
                            if (mapping.Components.Count > i)
                            {
                                componentMapping = mapping.Components[i];
                            }
                            elementId = mapping.Id;
                        }
                        else
                        {
                            elementId = defaultElementId;
                        }
                        string defaultComponentId = elementId + (i + 1).ToString("d2");
                        xml.Add(MapComponent(component, componentMapping, defaultComponentId));
                    }
                }
                repetitions.Add(xml);
            }
            return(repetitions);
        }