private void mainWindow_Load(object sender, EventArgs e) { DirectoryInfo linkDir = new DirectoryInfo("Links"); if (!linkDir.Exists) { linkDir.Create(); } foreach (FileInfo fi in linkDir.GetFiles("*.dll")) { try { Assembly asm = Assembly.LoadFile(fi.FullName); foreach (Type t in asm.GetTypes()) { if (!typeof(ILink).IsAssignableFrom(t)) { continue; } ILink loadedLink = (ILink)Activator.CreateInstance(t); LinkToolStripMenuItem linkItem = new LinkToolStripMenuItem(loadedLink); linkItem.Click += LinkItem_Click; this.tsmAdd.DropDownItems.Add(linkItem); } } catch (Exception ex) { Debug.Write(ex.ToString(), "Loading Chain"); throw; } } }
private void LinkItem_Click(object sender, EventArgs e) { LinkToolStripMenuItem linkStrip = sender as LinkToolStripMenuItem; ILink link = linkStrip.AssociatedLink; if (link == null) { return; } ListViewItem i = new LinkListViewItem(link); lvChain.Items.Add(i); }