internal void AddNewEntry(PropertyWrapper <TMenu> wrapper, MenuAttribute settings) { if (settings.orderInSection > 0) { this.sectionMembers.Add(settings.orderInSection, wrapper); } else { this.sectionMembers.Add(this.defaultPosition++, wrapper); } if (settings.sectionOrder != 0) { this.order = settings.sectionOrder; } }
static MenuStructure() { foreach (var property in typeof(TMenu).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)) { var settings = property.GetCustomAttribute <MenuAttribute>(); if (settings == null) { Main.LogI("Skipped property: " + property.Name); continue; } var wrapper = PropertyWrapper <TMenu> .CreatePropertyWrapper(property, settings); if (wrapper != null) { var sectionName = settings.sectionName; if (String.IsNullOrEmpty(sectionName)) { wrappers.Add(wrapper); } else { if (!sections.ContainsKey(sectionName) || sections[sectionName] == null) { sections[sectionName] = new MenuSection <TMenu>(sectionName); } sections[sectionName].AddNewEntry(wrapper, settings); } } } foreach (var sectionKV in sections) { if (sectionKV.Value.order > 0) { sortedSections.Add(sectionKV.Value.order, sectionKV.Value); } else { sortedSections.Add(defaultPosition++, sectionKV.Value); } } }