扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:Sunmast翻译 来源:论坛 2007年11月13日
关键字:
public interface IPlug { IPlugData[] GetData(); PlugDataEditControl GetEditControl(IPlugData Data); bool Save(string Path); bool Print(PrintDocument Document); } |
列表二:The PlugDisplayNameAttribute class definition
[AttributeUsage(AttributeTargets.Class)] public class PlugDisplayNameAttribute : System.Attribute { private string _displayName; public PlugDisplayNameAttribute(string DisplayName) : base() { _displayName=DisplayName; return; } public override string ToString() { return _displayName; } |
列表三:A partial listing of the EmployeePlug class definition
[PlugDisplayName("Employees")] [PlugDescription("This plug is for managing employee data")] public class EmployeePlug : System.Object, IPlug { public IPlugData[] GetData() { IPlugData[] data = new EmployeeData[] { new EmployeeData("Jerry", "Seinfeld") ,new EmployeeData("Bill", "Cosby") ,new EmployeeData("Martin", "Lawrence") }; return data; } public PlugDataEditControl GetEditControl(IPlugData Data) { return new EmployeeControl((EmployeeData)Data); } public bool Save(string Path) { //implementation not shown } public bool Print(PrintDocument Document) { //implementation not shown } } |
列表四:The method LoadPlugs
private void LoadPlugs() { string[] files = Directory.GetFiles("Plugs", "*.plug"); foreach(string f in files) { try { Assembly a = Assembly.LoadFrom(f); System.Type[] types = a.GetTypes(); foreach(System.Type type in types) { if(type.GetInterface("IPlug")!=null) { if(type.GetCustomAttributes(typeof(PlugDisplayNameAttribute), false).Length!=1) throw new PlugNotValidException(type, "PlugDisplayNameAttribute is not supported"); if(type.GetCustomAttributes(typeof(PlugDescriptionAttribute), false).Length!=1) throw new PlugNotValidException(type, "PlugDescriptionAttribute is not supported"); _tree.Nodes.Add(new PlugTreeNode(type)); } } } catch(Exception e) { MessageBox.Show(e.Message); } } return; } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者