public interface IApplicationObject { void Alert( string msg ); // 产生一条信息 void ShowInStatusBar( string msg ); // 将指定的信息显示在状态栏 IDocumentObject QueryCurrentDocument(); // 获取当前使用的文档对象 IDocumentObject[] QueryDocuments(); // 获取所有的文档对象 // 设置事件处理器 void SetDelegate( Delegates whichOne , EventHandler targer ); } // 目前只需要这一个事件 public enum Delegates { Delegate_ActiveDocumentChanged , } |
/// /// 编辑器对象必须实现这个接口 /// public interface IDocumentObject { // 这些属性是 RichTextBox 控件的相应的属性映射 string SelectionText { get ; set ; } Color SelectionColor { get ; set ; } Font SelectionFont { get ; set ; } int SelectionStart { get ; set ; } int SelectionLength { get ; set ; } string SelectionRTF { get ; set ; } bool HasChanges { get ; } void Select( int start , int length ); void AppendText( string str ); void SaveFile( string fileName ); void SaveFile(); void OpenFile( string fileName ); void CloseFile(); } |
/// /// 本程序的插件必须实现这个接口 /// public interface IPlugin { ConnectionResult Connect( IApplicationObject app ); void OnDestory(); void OnLoad(); void Run(); } /// /// 表示插件与主程序连接的结果 /// public enum ConnectionResult { Connection_Suclearcase/" target="_blank" >ccess , Connection_Failed } |
/// /// 用来指定一个插件的相关信息 /// public class PluginInfoAttribute : System.Attribute { /// /// Deprecated. Do not use. /// public PluginInfoAttribute() {} public PluginInfoAttribute( string name , string version , string author , string webpage , bool loadWhenStart ) { // 细节已略去 } public string Name { get { return _Name; } } public string Version { get { return _Version; } } public string Author { get { return _Author; } } public string Webpage { get { return _Webpage; } } public bool LoadWhenStart { get { return _LoadWhenStart; } } /// /// 用来存储一些有用的信息 /// public object Tag { get { return _Tag; } set { _Tag = value ; } } /// /// 用来存储序号 /// public int Index { get { return _Index; } set { _Index = value ; } } private string _Name = ""; private string _Version = ""; private string _Author = ""; private string _Webpage = ""; private object _Tag = null ; private int _Index = 0; // 暂时不会用 private bool _LoadWhenStart = true ; } |
/// /// My Pluging 1( Just for test ) /// [ PluginInfo("My Pluging 1( Just for test )" ,"1.0" , "Jack H Hansen" , "http://blog.csdn.net/matrix2003b" , true ) ] public class MyPlugin1 : IPlugin { public MyPlugin1() { } #region IPlugin 成员 // 细节已略去 #endregion private IApplicationObject _App; private IDocumentObject _CurDoc; } |
private bool IsValidPlugin( Type t ) { bool ret = false ; Type[] interfaces = t.GetInterfaces(); foreach ( Type theInterface in interfaces ) { if ( theInterface.FullName == "CSPluginKernel.IPlugin" ) { ret = true ; break ; } } return ret; } |
plugins.Add( pluginAssembly.CreateInstance( plugingType.FullName ) ); |