Exemplo n.º 1
0
        /// <summary>
        /// Finds the next segment by full name
        /// </summary>
        /// <param name="segmentFullName">The segment full name (name + value).</param>
        /// <returns>
        /// The found segment.
        /// </returns>
        public ParseTree FindNextSegment(SegmentFullName segmentFullName)
        {
            // Look on the same level first
            foreach (var child in Parent.Children.Skip(GetIndex()))
            {
                if (child.IsSegment && child.IsEqual(segmentFullName))
                {
                    return(child);
                }

                if (child.IsGroup && child.Children.First().IsEqual(segmentFullName))
                {
                    return(child.Children.First());
                }

                // Search a level down
                if (child.IsAll || child.IsChoice || child.IsLoopOfLoops)
                {
                    return(child.Children.First().FindNextSegment(segmentFullName));
                }
            }

            // Search a level up
            return(Parent.FindNextSegment(segmentFullName));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Compare a parse tree to identity
        /// </summary>
        /// <param name="segmentFullName">The identity</param>
        /// <returns>If equal</returns>
        public bool IsEqual(SegmentFullName segmentFullName)
        {
            // The names must match
            if (EdiName == segmentFullName.Name)
            {
                // If no identity match is required, mark this as a match
                if (string.IsNullOrEmpty(segmentFullName.Value))
                {
                    return(true);
                }

                // Match the value
                // This must have been defined in the enum of the first element of the segment.
                return(!Values.Any() || Values.Contains(segmentFullName.Value));
            }

            return(false);
        }