Ejemplo n.º 1
0
        private static MenuItem Join(IEnumerable <MenuItem> items)
        {
            var list = items.ToArray();

            if (list.Count() < 2)
            {
                return(list.Single());
            }

            var joined = new MenuItem
            {
                Text            = list.First().Text,
                Classes         = list.Select(x => x.Classes).FirstOrDefault(x => x != null && x.Count > 0),
                Url             = list.Select(x => x.Url).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)),
                Href            = list.Select(x => x.Href).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)),
                RouteValues     = list.Select(x => x.RouteValues).FirstOrDefault(x => x != null),
                LocalNavigation = list.Any(x => x.LocalNavigation),
                Position        = SelectBestPositionValue(list.Select(x => x.Position)),
                Items           = Merge(list.Select(x => x.Items)).ToArray()
            };

            return(joined);
        }
        private static MenuItem Join(IEnumerable<MenuItem> items)
        {
            var list = items.ToArray();

            if (list.Count() < 2)
                return list.Single();

            var joined = new MenuItem
            {
                Text = list.First().Text,
                Classes = list.Select(x => x.Classes).FirstOrDefault(x => x != null && x.Count > 0),
                Url = list.Select(x => x.Url).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)),
                Href = list.Select(x => x.Href).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)),
                RouteValues = list.Select(x => x.RouteValues).FirstOrDefault(x => x != null),
                LocalNavigation = list.Any(x => x.LocalNavigation),
                Position = SelectBestPositionValue(list.Select(x => x.Position)),
                Items = Merge(list.Select(x => x.Items)).ToArray()
            };

            return joined;
        }