下面分析用xml描述文件的方式来进行插件定义

定义扩展点如下:

public interface ISnippetProvider

{

string GetText (string shortcut);

}

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

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; }

}

到目前位置,扩展点和扩展都已经定义好了,现在使用xml文件来将进行插件的定义,具体如下:

<addin id="SnippetsAddinNode" version="1.0" >

<Dependencies>

<Addin id="TextEditorExtensionNode.Core" version="1.0"/>

</Dependencies>

<ExtensionPoint path="/SnippetsAddinNode/StockSnippets"  name="StockSnippets">

<ExtensionNode name="Command"/>

</ExtensionPoint>

<Extension path = "/SnippetsAddinNode/StockSnippets">

<Command  type="SnippetAttribute"  Shortcut="c"  Text="Hello"/>

<Command  type="SnippetAttribute"  Shortcut="for"  Text="for (int n=0; n &lt len; n++)\n{\n\t=&lt|&gt\n}"/>

<Command  type="SnippetAttribute"  Shortcut="foreach"  Text="foreach (var item in col)\n{\n\t&lt|&gt\n}"/>

</Extension>

</addin>

使用扩展点的代码如下:

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

{

string fullText = provider.GetText (word);

}

注意: xml配置方式定义的扩展点,支持以嵌入式资源方式和程序集一起发布,也支持配置文件以单独的文件的方式来部署

下一篇将详细参数扩展点的几种方式

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

  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 学习笔记 1

    Mono Addin是一个开源的插件框架,其主要支持的特性如下: The main features of Mono.Addins are: Supports descriptions of add- ...

  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. java集合-- arraylist小员工项目

    import java.io.*; import java.util.ArrayList; public class Emexe { public static void main(String[] ...

  2. OC测试错误整理

    3. NSDictionary *dict = [NSDictionary dictionaryWithObject:@"a value" forKey:@"aKey&q ...

  3. AngularJs的UI组件ui-Bootstrap分享(三)——Accordion

    Accordion手风琴控件使用uib-accordion和uib-accordion-group指令. <script> angular.module('myApp', ['ui.boo ...

  4. A web crawler design for data mining

    Abstract The content of the web has increasingly become a focus for academic research. Computer prog ...

  5. SQLSTATE[HY000] [2003] Cant connect to MySQL server

    今天要连远程数据库,结果PHP报错 Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2003 ...

  6. 安装debian第一天遇到的几个问题及解决方案

    1.当我想要使用sudo时,提示 bash: sudo: command not found 一开始以为是PATH不对,就各种百度各种试 export PATH=${PATH}:$HOME/bin:/ ...

  7. Padding Oracle Attack的一些细节与实现

    Padding Oracle Attack还是颇具威力的,ASP.NET的Padding Oracle Attack被Pwnie评为2010年最佳服务端漏洞之一.还是看 Juliano Rizzo a ...

  8. RFID Hacking④:使用ProxMark3 破解门禁

    文中提及的部分技术可能带有一定攻击性,仅供安全学习和教学用途,禁止非法使用! 0×00 前言 国际黑客大会Defcon传统之一:开锁!因为黑客认为锁也是一种安全挑战.我们在黑客题材电影.电视剧中也常常 ...

  9. Apache Jena - A Bootstrap

    前言 这篇文档属探究立项性质,作为语义网和本体建模工作的延续. 依照NoSQL Distilled上的考察方法,将Apache Jena作为图数据库的泛型考察.   内容 多种出版物上声明主要有四类N ...

  10. C++中的vector

    opencv中用到了很多vector  整理一下 vector容器是一个模板类,可以存放任何类型的对象(但必须是同一类对象).vector对象可以在运行时高效地添加元素,并且vector中元素是连续存 ...