sharpdevelop中的addin檔案是一個xml檔案,sd的作者在其中設定了一些特定的規則,來描述菜單,工具欄,視圖的建立及dll的加載,
作者建立了一個addin類(代碼存在于addin.cs)來完成對addin檔案的操作
addin檔案其中包含了,作者,版本,描述,版權等等各個方面的資訊,
addin的一個例子
<addin name = "sharpdevelop core"
author = "mike krueger"
description = "ncvs core module"
version = "1.0.0">
<runtime>
<import assembly="sharpdevelop.base.dll"/>
<import assembly="csharpparser.dll"/>
</runtime>
</addin>
//簡化的對addin檔案的操作類
using system;
using system.collections.generic;
using system.text;
using system.xml;
using system.io;
using system.windows.forms;
using system.diagnostics;
namespace cslearn
{
/// <summary>
/// 讀取xml文本的一個類
/// </summary>
public class cxyxmlreader
{
public cxyxmlreader(string tpxmfile)
{
debug.assert(string.isnullorempty(xmlfile), "xml檔案不能為空");
this.xmlfile = tpxmfile;
initlization();
}
/// <summary>
/// 加載xml檔案 初始化變量,
/// </summary>
private void initlization()
system.diagnostics.debug.assert(file.exists(xmlfile), "配置檔案不存在");
xmldocument doc = new xmldocument();
doc.load(xmlfile);
try
{
//selectsinglenode中的參數注意大小寫
version = doc.selectsinglenode("addin/@version").value;
author = doc.selectsinglenode("addin/@author").value;
description = doc.selectsinglenode("addin/@description").value;
}
catch (exception ex)
//todo:處理異常
throw ex;
string xmlfile,author,description,version;
/// 配置檔案名
public string xmlfilename { set { xmlfile = value; } }
/// 作者
public string author { get { return author; } }
/// addin描述
public string description { get { return description; } }
/// 版本資訊
public string version { get { return version; } }
}
}
//類的使用方法
cxyxmlreader reader = new cxyxmlreader("xmlfile1.xml");
messagebox.show(reader.version);