private void VisitMenu(MenuEntry parent, object instance, MenuEntry rootMenu) { var type = instance.GetType(); var propertyInfos = type.GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (var propertyInfo in propertyInfos.OrderBy(x => this.Order(propertyInfos, x)).ToArray()) { var menuAttribute = propertyInfo.GetCustomAttribute <MenuAttribute>(); if (menuAttribute == null) { continue; } var propertyValue = propertyInfo.GetValue(instance); if (propertyValue == null) { throw new NullReferenceException($"{type.FullName} {propertyInfo.Name}"); } var menuItemName = menuAttribute.Name; if (string.IsNullOrEmpty(menuItemName)) { menuItemName = type.Name; } this.context.Container.BuildUp(propertyValue); var textureAttribute = propertyInfo.GetCustomAttribute <TextureAttribute>(); textureAttribute?.Load(this.context.Renderer); var menuItemEntry = new MenuEntry( menuItemName, textureAttribute?.TextureKey, this.viewRepository.GetMenuView(), this.context.Renderer, this.MenuConfig, propertyValue); this.VisitInstance(menuItemEntry, propertyValue, rootMenu); parent.AddChild(menuItemEntry); } }
private void VisitItem(MenuEntry parent, object instance, MenuEntry rootMenu) { var type = instance.GetType(); var propertyInfos = type.GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (var propertyInfo in propertyInfos.OrderBy(x => this.Order(propertyInfos, x)).ToArray()) { var menuItemAttribute = propertyInfo.GetCustomAttribute <ItemAttribute>(); if (menuItemAttribute == null) { continue; } var propertyValue = propertyInfo.GetValue(instance); if (propertyValue == null) { throw new NullReferenceException($"{type.FullName} {propertyInfo.Name}"); } var menuItemName = menuItemAttribute.Name; if (string.IsNullOrEmpty(menuItemName)) { menuItemName = propertyInfo.Name; } this.context.Container.BuildUp(propertyValue); var textureAttribute = propertyInfo.GetCustomAttribute <TextureAttribute>(); textureAttribute?.Load(this.context.Renderer); var view = this.viewRepository.GetView(propertyInfo.PropertyType); MenuItemEntry menuItemEntry; if (propertyInfo.GetCustomAttribute <PermaShowAttribute>() != null) { var tmp = new PermaMenuItemEntry( menuItemName, textureAttribute?.TextureKey, view, this.context.Renderer, this.MenuConfig, new ValuePropertyBinding(instance, propertyInfo)); tmp.RootMenuName = rootMenu.Name; this.permaItemEntries.Add(tmp); menuItemEntry = tmp; } else { menuItemEntry = new MenuItemEntry( menuItemName, textureAttribute?.TextureKey, view, this.context.Renderer, this.MenuConfig, new ValuePropertyBinding(instance, propertyInfo)); } var tooltip = propertyInfo.GetCustomAttribute <TooltipAttribute>(); if (tooltip != null) { menuItemEntry.Tooltip = tooltip.Text; } parent.AddChild(menuItemEntry); } }