public DemoSelector() { this.InitializeComponent(); Type[] types = GetDemos(); DemoType[] demoTypes = new DemoType[types.Length]; for (int index = 0; index < types.Length; ++index) { demoTypes[index] = new DemoType(types[index]); } Array.Sort <DemoType>(demoTypes, demoTypeComparer); Dictionary <string, ListViewGroup> groups = new Dictionary <string, ListViewGroup>(); lvDemos.Clear(); lvDemos.Columns.Add("Demo Names", lvDemos.Width - 24, HorizontalAlignment.Left); for (int index = 0; index < types.Length; ++index) { DemoType demoType = demoTypes[index]; PhysicsDemoAttribute att = demoType.DemoAttribute; ListViewGroup group; if (!groups.TryGetValue(att.Group, out group)) { group = new ListViewGroup(att.Group, HorizontalAlignment.Left); groups.Add(att.Group, group); lvDemos.Groups.Add(group); } ListViewItem item = new ListViewItem(att.Name, group); item.Tag = demoType; lvDemos.Items.Add(item); } }
public DemoType(Type type) { this.type = type; this.physicsDemoAttribute = (PhysicsDemoAttribute)(type.GetCustomAttributes(typeof(PhysicsDemoAttribute), false)[0]); this.constructor = type.GetConstructor(Type.EmptyTypes); }