codon只是一个xml文件(addin文件中)的一个节点,这个节点须有唯一的名字 以下是一个codon的创建过程,并不包括condtion
以下是调用的程序正常执行步骤的记录
public
class
Addin
...
{ // 从addin文件中分析出extension public void Initialize( string fileName) ... { switch (curEl.Name) ... { case " Runtime " : AddRuntimeLibraries(Path.GetDirectoryName(fileName), curEl); break ; case " Extension " : AddExtensions(curEl); break ; } } void AddExtensions(XmlElement el) ... { if (el.Attributes[ " path " ] == null ) ... { throw new AddInLoadException( " One extension node has no path attribute defined. " ); } Extension e = new Extension(el.Attributes[ " path " ].InnerText); // extension的path属性 AddCodonsToExtension(e, el, new ConditionCollection()); // 调用此函数来实例化,条件,与Icodon extensions.Add(e); } void AddCodonsToExtension(Extension e, XmlElement el, ConditionCollection conditions) ... { foreach ( object o in el.ChildNodes) ... { if ( ! (o is XmlElement)) ... { continue ; } XmlElement curEl = (XmlElement)o; switch (curEl.Name) ... { case " And " : // these nodes are silently ignored. case " Or " : case " Not " : case " Condition " : break ; case " Conditional " : // 建立conditional 集合 default : ICodon codon = AddInTreeSingleton.AddInTree.CodonFactory.CreateCodon( this , curEl); // 创建类的实例 } // 调用codonfactory public class CodonFactory ... { public ICodon CreateCodon(AddIn addIn, XmlNode codonNode) ... { CodonBuilder builder = codonHashtable[codonNode.Name] as CodonBuilder; if (builder != null ) ... { return builder.BuildCodon(addIn); // 创建类的实例 } throw new CodonNotFoundException(String.Format( " no codon builder found for <{0}> " , codonNode.Name)); } }// 类的condonbuilder public class CodonBuilder ... { public ICodon BuildCodon(AddIn addIn) ... { ICodon codon; try ... { // create instance (ignore case) codon = (ICodon)assembly.CreateInstance(ClassName, true ); // 调用assembly来创建类的实例,并转换为icodon接口 // set default values codon.AddIn = addIn; } catch (Exception) ... { codon = null ; } return codon; } }