private void MergeBasicMenus(MenuList menu, string pathPrefix = null) { if (string.IsNullOrWhiteSpace(pathPrefix)) { pathPrefix = ""; } else if (!pathPrefix.EndsWith("/", StringComparison.OrdinalIgnoreCase)) { pathPrefix += "/"; } foreach (var m in menu) { if (BasicMenus.TryGetValue(pathPrefix + m.path, out MenuItem bm)) { m.data.menu.title = bm.data.menu.title; m.data.menu.icon = bm.data.menu.icon; m.data.menu.order = bm.data.menu.order; } if (!m.ForceAdd) { // Adding menu items, which don't have Controller var list = BasicMenus.Where(b => b.Key.StartsWith(pathPrefix + m.path) && b.Value.ForceAdd).Select(b => b.Value).ToList(); if (list.Count > 0) { m.children.AddRange(list); } } MergeBasicMenus(m.children, pathPrefix + m.path); m.children = new MenuList(m.children.OrderBy(c => c.data.menu.order).ToArray()); } if (string.IsNullOrWhiteSpace(pathPrefix)) { // Adding root menu items, which don't have Controller var list = BasicMenus.Where(b => !menu.Any(m => b.Key.StartsWith(m.path))).Select(b => b.Value).ToList(); if (list.Count > 0) { menu.AddRange(list); menu.Sort((mi1, mi2) => { if (mi1?.data?.menu?.order == null && mi2?.data?.menu?.order == null) { return(0); } else if (mi1?.data?.menu?.order == null) { return(-1); } else if (mi2?.data?.menu?.order == null) { return(1); } else { return(mi1.data.menu.order.GetValueOrDefault().CompareTo(mi2.data.menu.order.GetValueOrDefault())); } }); } } }