当前位置: 首页 > news >正文

做手机网站给我一个网站2021

做手机网站,给我一个网站2021,品牌网站部门建设,宁远做网站msoer转自#xff1a;http://www.cnblogs.com/yunfeifei/p/3927663.html 前面说完了导入和导出的几种方法#xff0c;如果大家细心的话会注意到前面我们导出的都是类#xff0c;那么方法和属性能不能导出呢#xff1f;#xff1f;#xff1f;答案是肯定的#xff0c;下面就来… 转自http://www.cnblogs.com/yunfeifei/p/3927663.html 前面说完了导入和导出的几种方法如果大家细心的话会注意到前面我们导出的都是类那么方法和属性能不能导出呢答案是肯定的下面就来说下MEF是如何导出方法和属性的。 还是前面的代码第二篇中已经提供了下载链接大家可以下载学习。 首先来说导出属性因为这个比较简单和导出类差不多先来看看代码主要看我加注释的地方MusicBook.cs中的代码如下 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel.Composition;namespace MEFDemo {[Export(MusicBook)]public class MusicBook : IBookService{//导出私有属性[Export(typeof(string))]private string _privateBookName Private Music BookName;//导出公有属性[Export(typeof(string))]public string _publicBookName Public Music BookName;public string BookName { get; set; }}[Export(MathBook, typeof(IBookService))]public class MathBook : IBookService{public string BookName { get; set; }public string GetBookName(){return MathBook;}}[Export(HistoryBook, typeof(IBookService))]public class HistoryBook : IBookService{public string BookName { get; set; }public string GetBookName(){return HistoryBook;}}} program.cs中的代码如下 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using System.ComponentModel.Composition; using System.ComponentModel.Composition.Hosting;namespace MEFDemo {class Program{[ImportMany(MathBook)]public IEnumerableobject Services { get; set; }//导入属性这里不区分public还是private[ImportMany]public Liststring InputString { get; set; }static void Main(string[] args){Program pro new Program();pro.Compose();if (pro.Services ! null){foreach (var s in pro.Services){var ss (IBookService)s;Console.WriteLine(ss.GetBookName());}}foreach (var str in pro.InputString){Console.WriteLine(str);}Console.Read();}private void Compose(){var catalog new AssemblyCatalog(Assembly.GetExecutingAssembly());CompositionContainer container new CompositionContainer(catalog);container.ComposeParts(this);}} } 下面还用foreach遍历输出属性的值运行即可查看到结果。最后我会附上源码供大家下载这里就不再截图了。 下面说导出方法吧同理无论是公有方法还是私有方法都是可以导出的MusicBook代码如下 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel.Composition;namespace MEFDemo {[Export(MusicBook)]public class MusicBook : IBookService{//导出私有属性[Export(typeof(string))]private string _privateBookName Private Music BookName;//导出公有属性[Export(typeof(string))]public string _publicBookName Public Music BookName;public string BookName { get; set; }//导出公有方法[Export(typeof(Funcstring))]public string GetBookName(){return MusicBook;}//导出私有方法[Export(typeof(Funcint, string))]private string GetBookPrice(int price){return $ price;}}[Export(MathBook, typeof(IBookService))]public class MathBook : IBookService{public string BookName { get; set; }public string GetBookName(){return MathBook;}}[Export(HistoryBook, typeof(IBookService))]public class HistoryBook : IBookService{public string BookName { get; set; }public string GetBookName(){return HistoryBook;}}} program中的代码如下 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using System.ComponentModel.Composition; using System.ComponentModel.Composition.Hosting;namespace MEFDemo {class Program{[ImportMany(MathBook)]public IEnumerableobject Services { get; set; }//导入属性这里不区分public还是private[ImportMany]public Liststring InputString { get; set; }//导入无参数方法[Import]public Funcstring methodWithoutPara { get; set; }//导入有参数方法[Import]public Funcint,string methodWithPara { get; set; }static void Main(string[] args){Program pro new Program();pro.Compose();if (pro.Services ! null){foreach (var s in pro.Services){var ss (IBookService)s;Console.WriteLine(ss.GetBookName());}}foreach (var str in pro.InputString){Console.WriteLine(str);}//调用无参数方法if (pro.methodWithoutPara ! null){Console.WriteLine(pro.methodWithoutPara());}//调用有参数方法if (pro.methodWithPara ! null){Console.WriteLine(pro.methodWithPara(3000));}Console.Read();}private void Compose(){var catalog new AssemblyCatalog(Assembly.GetExecutingAssembly());CompositionContainer container new CompositionContainer(catalog);container.ComposeParts(this);}} } 导入导出方法用到了FuncT委托当然没有返回值的话可以用ActionT委托关于委托这里就不多说了大家可以自行百度。
http://wiki.neutronadmin.com/news/187464/

相关文章:

  • 运城市网站建设网站后台的作用
  • 湖北省住房和城乡建设厅网站的公示公告网站被k
  • 长春网站优化实战铜川市新区建设局网站
  • 在线音乐网站开发教程济宁网站建设神华
  • 股票交易平台app排行榜seo综合查询可以关了吗
  • 德国服务器网站搭建一个商城需要多少钱
  • 建设中的网站备案期间做什济南教育加盟网站建设
  • 视频网站建设难吗前端开发岗位职责
  • seo实训总结seo外链网站
  • 沙井网站制作联系电话如何制作动漫网站模板下载
  • 做网站需要什么服务器上海网站推广维新
  • 华强北 网站建设网站建设的基本因素是什么
  • 百度地图手机网站开发中小企业网络拓扑图绘制
  • wordpress在这个站点注册有个能写文章做任务的网站
  • 用淘宝做公司网站青海政企网站建设
  • 互联网网站开发创业计划书设计素材网站情人节
  • 公司建网站搭建服务器网站设计报价怎么做
  • 哪些公司需要做网站免费下载百度软件
  • php带数据库的网站市场营销公司
  • 莆系医疗网站建设软文推广法
  • 网站建站多钱简述微信营销的技巧
  • 网站宣传有文化事业建设费吗佛山建设网站公司
  • 浙江省建设执业资格中心网站国际新闻最新消息十条摘抄2022
  • 兼职网站的建设目标怎么写电脑网址大全
  • 苏州集团网站设计开发网站建设的部署
  • 团购网站APP怎么做wordpress 导航栏搜索
  • 高校门户网站的建设方案网络小说网站三巨头
  • 新闻类网站排版网站建设石河子网站建设公司
  • 网站设计与制作是网页吗计算机软件培训机构哪个好
  • 代刷网站建设不关站备案wordpress