Mono addin 学习笔记 2
下面分析用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 < len; n++)\n{\n\t=<|>\n}"/>
<Command type="SnippetAttribute" Shortcut="foreach" Text="foreach (var item in col)\n{\n\t<|>\n}"/>
</Extension>
</addin>
使用扩展点的代码如下:
foreach (ISnippetProvider provider in AddinManager.GetExtensionObjects <ISnippetProvider>())
{
string fullText = provider.GetText (word);
}
注意: xml配置方式定义的扩展点,支持以嵌入式资源方式和程序集一起发布,也支持配置文件以单独的文件的方式来部署
下一篇将详细参数扩展点的几种方式
Mono addin 学习笔记 2的更多相关文章
- Mono addin 学习笔记 4 再论数据扩展点(Data only extension point)
1. Attribute声明方式 定义扩展属性 [AttributeUsage(AttributeTargets.Assembly, AllowMultiple= true)] public clas ...
- Mono addin 学习笔记 3
典型的基于Mono addin插件框架的应用程序有以下一个部分组成: 1. 主应用程序:提供了一系列的扩展点(Extension Point)供其他应用进行扩展: 2. 扩展插件: 其部署结构图如下为 ...
- Mono addin 学习笔记 1
Mono Addin是一个开源的插件框架,其主要支持的特性如下: The main features of Mono.Addins are: Supports descriptions of add- ...
- Mono addin 学习笔记 5 TypeExtensionPoint
1. Attribute声明方式 定义扩展点: [TypeExtensionPoint]public interface ICommand{ void Run();} 定义扩展: [Ex ...
- NGUI 学习笔记实战之二——商城数据绑定(Ndata)
上次笔记实现了游戏商城的UI界面,没有实现动态数据绑定,所以是远远不够的.今天采用NData来做一个商城. 如果你之前没看过,可以参考上一篇博客 NGUI 学习笔记实战——制作商城UI界面 ht ...
- MVC_学习笔记_2_Authorize
MVC5_学习笔记_2_Authorize/* GitHub stylesheet for MarkdownPad (http://markdownpad.com) *//* Author: Nico ...
- C#.NET学习笔记1---C#.NET简介
C#.NET学习笔记1---C#.NET简介 技术qq交流群:JavaDream:251572072 教程下载,在线交流:创梦IT社区:www.credream.com -------------- ...
- VSTO学习笔记(十四)Excel数据透视表与PowerPivot
原文:VSTO学习笔记(十四)Excel数据透视表与PowerPivot 近期公司内部在做一种通用查询报表,方便人力资源分析.统计数据.由于之前公司系统中有一个类似的查询使用Excel数据透视表完成的 ...
- VSTO 学习笔记(十二)自定义公式与Ribbon
原文:VSTO 学习笔记(十二)自定义公式与Ribbon 这几天工作中在开发一个Excel插件,包含自定义公式,根据条件从数据库中查询结果.这次我们来做一个简单的测试,达到类似的目的. 即在Excel ...
随机推荐
- CSS垂直居中指南
大概整理下css中的垂直居中问题 主要分两大类 1 知道块元素尺寸,一般就是指知道元素高度. 方法一:最简单的,类比水平居中. 思路:子元素设置为absolute; top bottom都设置为0 ...
- 实验一《开发环境的熟悉》&实验二《固件设计》
20145312&20145338 实验一<开发环境的熟悉>&实验二<固件设计> 合作博客链接:http://www.cnblogs.com/yx2014531 ...
- VS2015打开工程 未能正确加载“”包的问题
启动vs2015专业版时,出现类似于这样的提示框,有好几个,点击是或否,但下次打开还是会出现.寻找了网上的一些解决办法,例如用vs命令窗口或其他,但都无疾而终,下面提供的这个办法,顺利解决此问题 1. ...
- Python学习路程day11
SqlAlchemy ORM SQLAlchemy是Python编程语言下的一款ORM框架,该框架建立在数据库API之上,使用关系对象映射进行数据库操作,简言之便是:将对象转换成SQL,然后使用数据A ...
- python模块之collections
我们都知道,Python拥有一些内置的数据类型,比如str, int, list, tuple, dict等, collections模块在这些内置数据类型的基础上,提供了几个额外的数据类型: (1) ...
- HDU 2176
http://acm.hdu.edu.cn/showproblem.php?pid=2176 nim博弈的模型.要输出先手第一次取的情况,考虑角度是留给对手必败态 #include <iostr ...
- Conntect Bluetooth devices in iOS.
I understand that the External Accessory framework in iOS 3.0 and later will allow my application to ...
- 使用JavaScript设置、获取父子页面中的值
一:获取父页面中的值 有二种方法windows.open()和windows.showModalDialog() 1.windos.open(URL,name,reatures,replace) 再父 ...
- windows环境下 svn 客户端
- [原创]cocos2d-x研习录-第二阶 概念类之精灵类(CCSprite)
上一节说布景层CCLayer是小容器,那么精灵类CCSprite就是容器添加的内容,它是构成游戏的主要元素.精灵这个名称应该是游戏专用,它表示游戏中玩家操作的主角.敌人.NPC(Non Player ...