现在有这样一个问题: 一个Codon是如何变成 System.Windows.Forms.MenuStripCommand的? 这些就是doozers完成的:Doozers是一些helper类,它们会根据codons来生成一些对象。 下面是MenuItemDoozer的一个简化版本: public class MenuItemDoozer : IDoozer { // More on HandleConditions in the conditions section. public bool HandleConditions { get { return true; } } public object BuildItem(object caller, Codon codon, ArrayList subItems) { if (codon.Properties.Contains("type")) type = codon.Properties["type"]; else type = "Command"; switch (type) { case "Separator": return new MenuSeparator(codon, caller); case "CheckBox": return new MenuCheckBox(codon, caller); case "Item": return new MenuCommand(codon, caller); case "Command": return new MenuCommand(codon, caller); case "Menu": return new Menu(codon, caller, subItems); case "Builder": return codon.AddIn.CreateObject(codon.Properties["class"]); default: throw new NotSupportedException(type); } } } 其中的类“MenuCommand”, “MenuCheckBox” 是 SharpDevelop中override系统标准的“MenuStripCommand”的类. 它们会从codon的属性里取出label, icon 和shortcut等信息。 当一个MenuCommand被点击时,MenuCommand 会调用 “codon.AddIn.CreateObject()”来创建一个对象,把此对象转换成ICommand 接口后,再调用此接口的Run函数. How to add custom doozers 核心的doozers会把SD直接创建加载的. 但是如果你想在你的插件里定义自己的doozer该如何做呢?要想完成这一点,你可以把你的doozer 写到<Runtime> 段里。比如: <Import assembly = 'MyAddIn.dll'> <Doozer name='MyDoozer' class = 'MyAddIn.MyDoozer'/> </Import> 一般情况下,这个doozer (和assembly)在第一次使用时就会被加载进来。 |
| ||||