首页 > 应用开发 > IT综合 > Visual C# 插件构架实战之二(转)
| /// /// 本程序的插件必须实现这个接口 /// public interface IPlugin { ConnectionResult Connect( IApplicationObject app ); void OnDestory(); void OnLoad(); void Run(); } /// /// 表示插件与主程序连接的结果 /// public enum ConnectionResult { Connection_Success , 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 ) ); |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/79548/viewspace-926549/ ,如需转载,请注明出处,否则将追究法律责任。