c# - How do I populate the listbox plugin item Name as it is set in the Plugin interface? -
when plugin buttons loaded, button gets populated name of iplugin interface asks in method string name { get; }
i’m trying listbox item populate name same way doing button.
private void assemblecomponents
private void assemblecomponents(object sender) { icollection<iplugin> plugins = genericpluginloader<iplugin>.loadplugins("plugins"); string selection = ""; if (sender listbox) { if (((listbox)sender).selectedvalue != null) selection = ((listbox)sender).selectedvalue.tostring(); } string path = system.io.path.combine(appdomain.currentdomain.basedirectory, "plugins"); directorycatalog cat = new directorycatalog(path); //icollection<iplugin> plugins = pluginloader.loadplugins("plugins"); foreach (var item in plugins) { //add if not present if (!_plugins.containskey(item.name)) { string dllname = getdllname(item.name); button b = new button() { name = dllname.replace(".", "").toupper(), content = item.name, visibility = system.windows.visibility.hidden }; b.click += b_click; plugingrid.children.add(b); _plugins.add(item.name, item); // this.plugingrid.children.clear(); //by vasey } } // make visible selected plugin button foreach (var ctl in plugingrid.children) { if (ctl button) { button button = (button)ctl; if (button.name.equals(selection.replace(".", "").toupper())) { button.visibility = system.windows.visibility.visible; } else { button.visibility = system.windows.visibility.hidden; } } } }
string getdllname
string getdllname(string name) { string ret = ""; name = name.replace(" ", ""); // strip spaces assembly asm = appdomain.currentdomain.getassemblies(). singleordefault(assembly => assembly.getname().name == name); if (asm != null) { ret = path.getfilenamewithoutextension(asm.location); } return ret; }
private void lbfiles_selectionchanged
private void lbfiles_selectionchanged(object sender, selectionchangedeventargs e) { assemblecomponents(sender); }
how can implement this?
Comments
Post a Comment