示例#1
0
        public virtual IEnumerable <Tag> Apply(IEnumerable <Tag> tags)
        {
            foreach (var tag in tags)
            {
                var start = tag.Parent.Children.OfType <Tag>().First(t => t.TagName == tag.TagName);

                List <Tag> siblingTags = new List <Tag>()
                {
                    start
                };

                var sibling = start.NextSibling;
                while (sibling != null)
                {
                    Tag siblingTag = sibling as Tag;
                    if (siblingTag != null && siblingTag.TagName == tag.TagName)
                    {
                        siblingTags.Add(siblingTag);
                    }
                    sibling = sibling.NextSibling;
                }

                foreach (var index in expression.GetValues().TakeWhile(n => n <= siblingTags.Count))
                {
                    if (index > 0)
                    {
                        yield return(siblingTags[index - 1]);
                    }
                }
            }
        }
示例#2
0
        public IEnumerable <Tag> Apply(IEnumerable <Tag> tags)
        {
            foreach (var tag in tags)
            {
                List <Tag> siblingTags = new List <Tag>()
                {
                    tag
                };
                var sibling = tag.NextSibling;
                while (sibling != null)
                {
                    Tag siblingTag = sibling as Tag;
                    if (siblingTag != null && siblingTag.TagName == tag.TagName)
                    {
                        siblingTags.Add(siblingTag);
                    }
                    sibling = sibling.NextSibling;
                }

                foreach (var index in expression.GetValues().TakeWhile(n => n > 0))
                {
                    if (index <= siblingTags.Count)
                    {
                        yield return(siblingTags[siblingTags.Count - index]);
                    }
                }
            }
        }
示例#3
0
 public IEnumerable <Tag> Apply(IEnumerable <Tag> tags)
 {
     foreach (var tag in tags)
     {
         IList <Tag> childrenTags = tag.Children.OfType <Tag>().ToList();
         foreach (var index in expression.GetValues().TakeWhile(n => n <= tag.Children.Count))
         {
             if (index > 0)
             {
                 yield return(childrenTags[index - 1]);
             }
         }
     }
 }