实际一个多态(或弱类型)ConfigurationElementCollection

不知道你们有没有过这样的一个需求:

     假如我要实现一个像Windows的任务计划一样的工具。我支持按天执行,或按月执行,甚至我还直接按每个星期几来执行。好吧,做这样一个东西不难。现在我希望把这些运行信息存在配置文件中。那么配置文件可能是这样的结构

  

  <scheduleServiceSection>
    <schedules>
      <add name ="DaySchedule" 
           days="1" startDateTime="2012/11/30 11:59:59" endDateTime="2013/11/30 11:59:59" runTime="11:59:59" >
      </add>
    

      <add name ="MonthSchedule" 
     months="1" runMonths="1,2,3,4,5,6,7,8,9,10,11,12"
           runDays="1,2,3,4,5"
           startDateTime="2012/11/30 11:59:59" endDateTime="2013/11/30 11:59:59" runTime="11:59:59" >
      </add>

      <add name ="WeekSchedule"
     weeks="1" runWeekDays="0,1,2,3,4,5,6"
     startDateTime="2012/11/30 11:59:59" endDateTime="2013/11/30 11:59:59" runTime="11:59:59" >

      </add>
    </schedules>
  </scheduleServiceSection>

 .net 自带的配置集合 ConfigurationElementCollection,只能包含一种类型的ConfigurationElement。不能实现像上面那种WeekSchedule比DaySchedule多一些属性或少一些属性。

解决办法:

https://github.com/Yunanw/CSSnippet/tree/master/PolyConfigCollection

转载于:https://www.cnblogs.com/listhome/archive/2012/12/11/2807625.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值