Mono Addin是一个开源的插件框架,其主要支持的特性如下:

The main features of Mono.Addins are:

  • Supports descriptions of add-ins using custom attributes (for simple and common extensions) or using an xml manifest (for more complex extensibility needs).
  • Support for add-in hierarchies, where add-ins may depend on other add-ins.
  • Lazy loading of add-ins.
  • Provides an API for accessing to add-in descriptions, which will allow building development and documentation tools for handling add-ins.
  • Dynamic activation / deactivation of add-ins at run time.
  • Allows sharing add-in registries between applications, and defining arbitrary add-in locations.
  • Allows implementing extensible libraries.
  • Supports add-in localization.
  • In addition to the basic add-in engine, it provides a Setup library to be used by applications which want to offer basic add-in management features to users, such as enabling/disabling add-ins, or installing add-ins from on-line repositories.

(来自mono官方网站的解释,http://www.mono-project.com/Mono.Addins

大概意思是:

1. 支持用自定义属性(Attribute,简单项目)和xml定义(大型项目);

2. 支持插件层次结构,允许插件之间相互依赖(插件本身可以定义扩展点供其他插件进行扩展)

3. 支持插件懒加载;

4. 提供了访问插件描述的API接口;

5. 支持运行期激活/关闭插件;

6. 主持在应用程序之间共享插件,也允许插件私有;

7. 支持可扩展的类库;

8. 本地化支持;

9. 除了提供插件引擎外,还提供了安装工具,用于提供安装/卸载插件、启用/禁用插件

下面分析用Attribute声明的方式来进行插件定义

定义扩展点如下:

 [TypeExtensionPoint] //定义扩展点的属性
 public interface ISnippetProvider
 {
  string GetText (string shortcut);
 }

下面定义基于该扩展点的扩展如下:

[Extension] // 扩展点属性
 class StockSnippetProvider: ISnippetProvider
 {
     public string GetText (string shortcut)
    {
            foreach (ExtensionNode<SnippetAttribute> node in AddinManager.GetExtensionNodes("/SnippetsAddinNode/StockSnippets"))
            {
                  if (node.Data.Shortcut == shortcut)
                      return node.Data.Text;
             }
           return null;
     }
 }

//定义扩展属性如下:

[AttributeUsage (AttributeTargets.Assembly, AllowMultiple=true)]

public class SnippetAttribute : CustomExtensionAttribute  

{

public SnippetAttribute ()

{   }

public SnippetAttribute ([NodeAttribute ("Shortcut")] string shortcut, [NodeAttribute ("Text")] string text)

{

Shortcut = shortcut;

Text = text;

}

[NodeAttribute]

public string Shortcut { get; set; }

[NodeAttribute]

public string Text { get; set; }

}

到目前位置,扩展点和扩展都已经定义好了,现在使用属性来生命扩展点,并定义几个扩展:

声明扩展点如下:

[assembly: ExtensionPoint("/SnippetsAddinNode/StockSnippets", ExtensionAttributeType = typeof(SnippetAttribute))]

声明扩展如下:

[assembly: Snippet("foreach", "foreach (var item in col)\n{\n\t<|>\n}")]

[assembly: Snippet("for", "for (int n=0; n<len; n++)\n{\n\t<|>\n}")]

[assembly: Snippet("c", "hello,world!")]

使用扩展点的代码如下:

foreach (ISnippetProvider provider in AddinManager.GetExtensionObjects <ISnippetProvider>())

{

string fullText = provider.GetText (word);

}

下一篇将分析用xml描述文件的方式来定义插件

Mono addin 学习笔记 1的更多相关文章

  1. Mono addin 学习笔记 4 再论数据扩展点(Data only extension point)

    1. Attribute声明方式 定义扩展属性 [AttributeUsage(AttributeTargets.Assembly, AllowMultiple= true)] public clas ...

  2. Mono addin 学习笔记 3

    典型的基于Mono addin插件框架的应用程序有以下一个部分组成: 1. 主应用程序:提供了一系列的扩展点(Extension Point)供其他应用进行扩展: 2. 扩展插件: 其部署结构图如下为 ...

  3. Mono addin 学习笔记 2

    下面分析用xml描述文件的方式来进行插件定义 定义扩展点如下: public interface ISnippetProvider { string GetText (string shortcut) ...

  4. Mono addin 学习笔记 5 TypeExtensionPoint

    1. Attribute声明方式 定义扩展点: [TypeExtensionPoint]public interface ICommand{        void Run();} 定义扩展: [Ex ...

  5. NGUI 学习笔记实战之二——商城数据绑定(Ndata)

    上次笔记实现了游戏商城的UI界面,没有实现动态数据绑定,所以是远远不够的.今天采用NData来做一个商城. 如果你之前没看过,可以参考上一篇博客   NGUI 学习笔记实战——制作商城UI界面  ht ...

  6. MVC_学习笔记_2_Authorize

    MVC5_学习笔记_2_Authorize/* GitHub stylesheet for MarkdownPad (http://markdownpad.com) *//* Author: Nico ...

  7. C#.NET学习笔记1---C#.NET简介

    C#.NET学习笔记1---C#.NET简介 技术qq交流群:JavaDream:251572072  教程下载,在线交流:创梦IT社区:www.credream.com -------------- ...

  8. VSTO学习笔记(十四)Excel数据透视表与PowerPivot

    原文:VSTO学习笔记(十四)Excel数据透视表与PowerPivot 近期公司内部在做一种通用查询报表,方便人力资源分析.统计数据.由于之前公司系统中有一个类似的查询使用Excel数据透视表完成的 ...

  9. VSTO 学习笔记(十二)自定义公式与Ribbon

    原文:VSTO 学习笔记(十二)自定义公式与Ribbon 这几天工作中在开发一个Excel插件,包含自定义公式,根据条件从数据库中查询结果.这次我们来做一个简单的测试,达到类似的目的. 即在Excel ...

随机推荐

  1. vs2008编译openssl问题

    运行openssl demo 时,debug 版本正常,release 版本报异常:OPENSSL_Uplink(585E6000,08): no OPENSSL_Applink .demo 编译环境 ...

  2. Linux在目录中查找某个函数

    1,在某个路径下查文件. 在/etc下查找“*.log”的文件 find /etc -name “*.log” 2,扩展,列出某个路径下所有文件,包括子目录. find /etc -name “*” ...

  3. CodeForces 686A-Free Ice Cream

    题目: 儿童排队领冰激凌,给你两个数n,x分别代表接下来有n行与初始的冰激淋数:接下来n行,每行有一个字符('+'or‘-’),还有一个整数d,+d表示新增的冰激 凌数(由搬运工搬运到此),-d表示儿 ...

  4. hdu 1039 (string process, fgets, scanf, neat utilization of switch clause) 分类: hdoj 2015-06-16 22:15 38人阅读 评论(0) 收藏

    (string process, fgets, scanf, neat utilization of switch clause) simple problem, simple code. #incl ...

  5. 团队开发——冲刺2.b

    冲刺阶段二(第二天) 1.昨天做了什么? 收集游戏图片:开始.暂停.继续.重新开始.退出……为了界面的后期美工做准备. 2.今天准备做什么? 把“开始游戏”.“退出游戏”.“取消”等文字按钮加工成游戏 ...

  6. React Native中的网络请求fetch和简单封装

    React Native中的网络请求fetch使用方法最为简单,但却可以实现大多数的网络请求,需要了解更多的可以访问: https://segmentfault.com/a/1190000003810 ...

  7. JQuery Jsonp 跨域

    需求:两个不同域的网站想利用ajax交互数据 客户端:ajax的dataType参数设置成jsonp,然后设置一个回调函数(jsonCallBack) 服务器端:返回callfunName([{a:& ...

  8. 传智播客JavaWeb day03

    ServletContext 这堂课主要讲ServletContext这个web域(可以看得见范围的)对象,web在启动的时候会创建唯一的ServletContext域对象. 作用:1.用来web域共 ...

  9. Android使用echarts框架的K线图

    百度echarts框架还是比较强大的,之前有尝试使用它,但毕竟主要使用于web网页端,效果不是很好,所以最终还是取消使用echarts 但之前在使用的过程中遇到些问题,虽然解决很简单,但也花了我不少时 ...

  10. Mac下Nginx环境配置

    环境信息: Mac OS X 10.11.1 Homebrew  0.9.5 正文 一.安装 Nginx 终端执行: brew search nginx brew install nginx 当前版本 ...