コード例 #1
0
        public static PropertyFindResult FindExistingElements(this Project project, params string[] names)
        {
            var result = new PropertyFindResult
            {
                OtherUnconditionalElements = new List <XElement>(),
                OtherConditionalElements   = new List <XElement>()
            };

            foreach (var name in names)
            {
                var(unconditional, conditional) = project.PropertyAll(name);
                foreach (var child in unconditional)
                {
                    Store(child, ref result.LastUnconditionalElement, result.OtherUnconditionalElements);
                }

                foreach (var(_, child) in conditional)
                {
                    Store(child, ref result.LastConditionalElement, result.OtherConditionalElements);
                }
            }

            return(result);

            void Store(XElement child, ref XElement lastElement, IList <XElement> others)
            {
                if (lastElement != null)
                {
                    if (child.IsAfter(lastElement))
                    {
                        others.Add(lastElement);
                        lastElement = child;
                    }
                    else
                    {
                        others.Add(child);
                    }
                }
                else
                {
                    lastElement = child;
                }
            }
        }
コード例 #2
0
 public static IEnumerable <XElement> All(this PropertyFindResult self)
 {
     return(self.LastElementIsConditional
                         ? self.AllConditional().Concat(self.AllUnconditional())
                         : self.AllUnconditional().Concat(self.AllConditional()));
 }
コード例 #3
0
 public static IEnumerable <XElement> AllConditional(this PropertyFindResult self)
 {
     return(self.LastConditionalElement != null
                         ? self.OtherConditionalElements.Concat(new[] { self.LastConditionalElement })
                         : Array.Empty <XElement>());
 }