ÓÑÇéÌáʾ£ºÈç¹û±¾ÍøÒ³´ò¿ªÌ«Âý»òÏÔʾ²»ÍêÕû£¬Çë³¢ÊÔÊó±êÓÒ¼ü¡°Ë¢Ð¡±±¾ÍøÒ³£¡
¸»Ê¿¿µÐ¡ËµÍø ·µ»Ø±¾ÊéĿ¼ ¼ÓÈëÊéÇ© ÎÒµÄÊé¼Ü ÎÒµÄÊéÇ© TXTÈ«±¾ÏÂÔØ ¡ºÊղص½ÎÒµÄä¯ÀÀÆ÷¡»

VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ62²¿·Ö

¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿! Èç¹û±¾ÊéûÓÐÔĶÁÍ꣬ÏëÏ´μÌÐø½Ó×ÅÔĶÁ£¬¿ÉʹÓÃÉÏ·½ "Êղص½ÎÒµÄä¯ÀÀÆ÷" ¹¦ÄÜ ºÍ "¼ÓÈëÊéÇ©" ¹¦ÄÜ£¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡With¡¡the¡¡ConfigurationLoader¡¡class¡¡defined¡¡as¡¡the¡¡class¡¡used¡¡to¡¡dynamically¡¡instantiate¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡other¡¡types£»¡¡the¡¡private¡¡class¡¡is¡¡declared¡¡as¡¡follows¡¡£¨added¡¡to¡¡the¡¡Definitions¡¡project£©£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Class¡¡ConfigurationLoader¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡_availableTypes¡¡As¡¡Dictionary£¨Of¡¡String£»¡¡ConfigurationInfo£©¡¡=¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡New¡¡Dictionary£¨Of¡¡String£»¡¡ConfigurationInfo£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡Class¡¡ConfigurationInfo¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡AssemblyName¡¡As¡¡String¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡EasyName¡¡As¡¡String¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡TypeName¡¡As¡¡String¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Class¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ConfigurationInfo¡¡contains¡¡three¡¡data¡¡members£º¡¡AssemblyName£»¡¡EasyName£»¡¡and¡¡TypeName¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡class¡¡is¡¡prefixed¡¡with¡¡Private£»¡¡indicating¡¡that¡¡nothing¡¡external¡¡to¡¡the¡¡ConfigurationLoader¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡class¡¡can¡¡see¡¡the¡¡configuration¡£¡¡Had¡¡ConfigurationInfo¡¡been¡¡declared¡¡with¡¡the¡¡¡¡Public¡¡keyword£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡following¡¡code¡¡would¡¡have¡¡been¡¡legal¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡cls¡¡As¡¡ConfigurationLoader¡£ConfigurationInfo¡¡=¡¡_¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡New¡¡ConfigurationLoader¡£ConfigurationInfo£¨£©¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡345¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡2¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡AP¡¡P¡¡L¡¡I¡¡CAT¡¡I¡¡ON¡¡¡¡¡¡CO¡¡N¡¡F¡¡IG¡¡U¡¡R¡¡AT¡¡IO¡¡N¡¡¡¡¡¡A¡¡N¡¡D¡¡¡¡¡¡D¡¡Y¡¡N¡¡A¡¡M¡¡IC¡¡¡¡¡¡L¡¡O¡¡AD¡¡IN¡¡G¡¡323¡¡



¡¡¡¡¡¡¡¡¡¡ConfigurationInfo¡¡is¡¡used¡¡to¡¡store¡¡the¡¡information¡¡from¡¡the¡¡configuration¡¡file¡£¡¡The¡¡config

uration¡¡information¡¡is¡¡cross¡­referenced¡¡using¡¡a¡¡Dictionary£»¡¡where¡¡the¡¡key¡¡is¡¡the¡¡EasyName¡¡data¡¡¡¡

member¡£¡¡

¡¡¡¡¡¡¡¡¡¡To¡¡parse¡¡the¡¡configuration¡¡information¡¡and¡¡create¡¡the¡¡individual¡¡instances¡¡of¡¡¡¡

ConfigurationInfo£»¡¡the¡¡following¡¡code¡¡£¨part¡¡of¡¡ConfigurationLoader£©¡¡is¡¡used¡£¡¡



Imports¡¡System¡£Configuration¡¡



Public¡¡Sub¡¡Load£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡Dim¡¡value¡¡As¡¡String¡¡=¡¡ConfigurationManager¡£AppSettings£¨¡¨assemblies¡¨£©¡¡

¡¡¡¡¡¡¡¡Dim¡¡values¡¡As¡¡String£¨£©¡¡=¡¡value¡£Split£¨¡¨£»¡¨c£©¡¡

¡¡¡¡¡¡¡¡Dim¡¡c1¡¡As¡¡Integer¡¡=¡¡0¡¡



¡¡¡¡¡¡¡¡Do¡¡While¡¡£¨c1¡¡¡¶¡¡values¡£Length£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡configInfo¡¡As¡¡New¡¡ConfigurationInfo£¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡configInfo¡£EasyName¡¡=¡¡values£¨c1£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡configInfo¡£TypeName¡¡=¡¡values£¨£¨c1¡¡£«¡¡1£©£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡configInfo¡£AssemblyName¡¡=¡¡values£¨£¨c1¡¡£«¡¡2£©£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_availableTypes¡£Add£¨values£¨c1£©£»¡¡configInfo£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡c1¡¡=¡¡£¨c1¡¡£«¡¡3£©¡¡

¡¡¡¡¡¡¡¡Loop¡¡¡¡

End¡¡Sub¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡configuration¡¡is¡¡read¡¡using¡¡AppSettings£»¡¡and¡¡then¡¡split¡¡into¡¡an¡¡array¡¡of¡¡string¡¡element¡¡¡¡

values¡£¡¡Processing¡¡three¡¡array¡¡elements¡¡at¡¡a¡¡time¡¡iterates¡¡the¡¡array¡£¡¡With¡¡every¡¡iteration£»¡¡an¡¡¡¡

instance¡¡of¡¡ConfigurationInfo¡¡is¡¡created¡£¡¡Once¡¡the¡¡buffer¡¡has¡¡been¡¡processed£»¡¡it¡¡is¡¡possible¡¡¡¡

to¡¡dynamically¡¡instantiate¡¡a¡¡type¡¡using¡¡the¡¡following¡¡ConfigurationLoader¡¡method¡£¡¡



Imports¡¡System¡£Reflection¡¡

¡£¡¡¡£¡¡¡£¡¡



¡¡¡¡¡¡¡¡Public¡¡Function¡¡Instantiate£¨Of¡¡RequestedType£©£¨ByVal¡¡identifier¡¡As¡¡String£©¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡As¡¡RequestedType¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡Not¡¡_availableTypes¡£ContainsKey£¨identifier£©¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Throw¡¡New¡¡ArgumentException£¨£¨¡¨identifier¡¡£¨¡¨¡¡&¡¡identifier¡¡&¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¨£©¡¡is¡¡not¡¡a¡¡listed¡¡type¡¨£©£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡info¡¡As¡¡ConfigurationInfo¡¡=¡¡_availableTypes¡£Item£¨identifier£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡assemblyName¡¡As¡¡AssemblyName¡¡=¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡AssemblyName¡£GetAssemblyName£¨info¡£AssemblyName£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨£¨¡¨assemblyname£¨¡¨¡¡&¡¡assemblyName¡£ToString£¨£©¡¡&¡¡¡¨£©¡¨£©£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡DirectCast£¨¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Assembly¡£Load£¨assemblyName£©¡£CreateInstance£¨info¡£TypeName£©£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡RequestedType£©¡¡

¡¡¡¡¡¡¡¡End¡¡Function¡¡



¡¡¡¡¡¡¡¡¡¡Look¡¡at¡¡the¡¡declaration¡¡of¡¡the¡¡method¡¡Instantiate£¨£©£»¡¡and¡¡you¡¡will¡¡see¡¡that¡¡it¡¡is¡¡a¡¡¡¡¡¡

generics¡¡method¡¡£¨discussed¡¡in¡¡Chapter¡¡11£©¡£¡¡The¡¡idea¡¡is¡¡to¡¡instantiate¡¡a¡¡type¡¡and¡¡perform¡¡an¡¡¡¡

automatic¡¡cast¡¡to¡¡the¡¡request¡¡type¡£¡¡It¡¡avoids¡¡needing¡¡to¡¡define¡¡Instantiate£¨£©¡¡using¡¡the¡¡Object¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡346¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

324¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡2¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡A¡¡PP¡¡L¡¡I¡¡CA¡¡TI¡¡O¡¡N¡¡¡¡¡¡CO¡¡N¡¡F¡¡I¡¡G¡¡U¡¡R¡¡AT¡¡IO¡¡N¡¡¡¡¡¡AN¡¡D¡¡¡¡¡¡D¡¡Y¡¡N¡¡A¡¡M¡¡I¡¡C¡¡¡¡L¡¡O¡¡AD¡¡I¡¡N¡¡G¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡type¡£¡¡The¡¡parameter¡¡identifier¡¡is¡¡a¡¡string¡¡that¡¡is¡¡used¡¡to¡¡search¡¡the¡¡Dictionary¡¡data¡¡member¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_availableTypes¡£¡¡If¡¡the¡¡identifier¡¡exists¡¡in¡¡_availableTypes£»¡¡the¡¡ConfigurationInfo¡¡instance¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡retrieved¡¡and¡¡used¡¡to¡¡instantiate¡¡the¡¡type¡£¡¡If¡¡the¡¡identifier¡¡does¡¡not¡¡exist£»¡¡an¡¡exception¡¡is¡¡thrown¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡bolded¡¡code¡¡is¡¡the¡¡special¡¡code¡¡because¡¡it¡¡is¡¡unlike¡¡what¡¡you¡¡have¡¡encountered¡¡thus¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡far¡¡in¡¡the¡¡book¡£¡¡Built¡¡into¡¡¡¡is¡¡the¡¡ability¡¡to¡¡dynamically¡¡execute¡¡code£»¡¡as¡¡illustrated¡¡here¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡first¡¡bolded¡¡line¡¡makes¡¡the¡¡reflection¡¡ability¡¡available£»¡¡and¡¡the¡¡second¡¡is¡¡used¡¡to¡¡load¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡assembly¡£¡¡So£»¡¡for¡¡example£»¡¡if¡¡the¡¡parameter¡¡identifier¡¡equaled¡¡Impl1¡¡£¨remember£»¡¡this¡¡is¡¡one¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡of¡¡the¡¡keys¡¡in¡¡the¡¡configuration¡¡file¡¡¡¡element£©£»¡¡the¡¡first¡¡bolded¡¡line¡¡would¡¡refer

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ence¡¡and¡¡dynamically¡¡load¡¡the¡¡assembly¡¡Implementations1¡£dll¡£¡¡However£»¡¡and¡¡here¡¡is¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡catch£»¡¡the¡¡assembly¡¡can¡¡be¡¡loaded¡¡dynamically¡¡only¡¡if¡¡Implementations1¡£dll¡¡exists¡¡in¡¡the¡¡local¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡directory¡¡or¡¡the¡¡GAC¡£¡¡As¡¡an¡¡alternative£»¡¡you¡¡could¡¡specify¡¡the¡¡entire¡¡path¡¡in¡¡the¡¡definition¡¡of¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡assembly¡£¡¡The¡¡downside¡¡to¡¡this¡¡strategy¡¡is¡¡that¡¡your¡¡assembly¡¡must¡¡always¡¡be¡¡located¡¡at¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡same¡¡place¡¡on¡¡different¡¡machines¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡the¡¡code¡¡assigns¡¡the¡¡variable¡¡assemblyName£»¡¡it¡¡is¡¡to¡¡a¡¡reference¡¡of¡¡a¡¡loaded¡¡¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡assembly¡£¡¡The¡¡assembly¡¡will¡¡be¡¡parsed£»¡¡and¡¡from¡¡there£»¡¡it¡¡is¡¡possible¡¡to¡¡instantiate¡¡a¡¡type¡£¡¡The¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡second¡¡bolded¡¡line¡¡calls¡¡the¡¡method¡¡CreateInstance£¨£©£»¡¡with¡¡the¡¡name¡¡of¡¡the¡¡type¡¡that¡¡you¡¡want¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡instantiate£»¡¡including¡¡the¡¡namespace¡£¡¡So£»¡¡for¡¡example£»¡¡if¡¡Implementations1¡£dll¡¡has¡¡been¡¡loaded£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡you¡¡could¡¡instantiate¡¡the¡¡type¡¡¡¡Implementations1¡£Implementation¡£¡¡The¡¡instantiation¡¡will¡¡work¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡even¡¡though¡¡Implementations1¡£Implementation¡¡is¡¡a¡¡private¡¡class£»¡¡because¡¡you¡¡are¡¡using¡¡dynamic¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡programming¡¡principles¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡However£»¡¡being¡¡able¡¡to¡¡instantiate¡¡the¡¡type¡¡does¡¡not¡¡imply¡¡being¡¡able¡¡to¡¡use¡¡the¡¡type¡£¡¡To¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡be¡¡able¡¡to¡¡use¡¡the¡¡instantiated¡¡type£»¡¡you¡¡need¡¡to¡¡be¡¡able¡¡to¡¡cast¡¡to¡¡a¡¡type¡¡that¡¡has¡¡been¡¡declared¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡publicly¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡We¡¡will¡¡continue¡¡the¡¡¡¡Implementations1¡£Implementation¡¡example¡¡and¡¡figure¡¡out¡¡how¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡instantiate¡¡and¡¡manipulate¡¡the¡¡instantiated¡¡object¡£¡¡But¡¡before¡¡we¡¡get¡¡to¡¡that¡¡code£»¡¡we¡¡need¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡talk¡¡about¡¡an¡¡additional¡¡programming¡¡feature£º¡¡singletons¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Using¡¡Singletons¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡class¡¡ConfigurationManager¡¡is¡¡a¡¡shared¡¡class¡¡in¡¡¡¡terms£»¡¡which¡¡means¡¡that¡¡you¡¡cannot¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡instantiate¡¡the¡¡class¡£¡¡In¡¡Visual¡¡Basic¡­speak£»¡¡a¡¡shared¡¡class¡¡is¡¡a¡¡module£»¡¡and¡¡a¡¡shared¡¡method¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡method¡¡marked¡¡Shared¡£¡¡A¡¡module£»¡¡shared¡¡methods£»¡¡and¡¡shared¡¡data¡¡members¡¡result¡¡in¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡single¡­instance¡¡class¡£¡¡Another¡¡way¡¡to¡¡get¡¡the¡¡same¡¡effect¡¡is¡¡to¡¡create¡¡a¡¡singleton¡£¡¡A¡¡singleton¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡behaves¡¡like¡¡a¡¡shared¡¡class£»¡¡except¡¡that¡¡the¡¡class¡¡is¡¡instantiated¡£¡¡An¡¡advantage¡¡of¡¡using¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡singleton¡¡approach¡¡is¡¡that¡¡you¡¡can¡¡have¡¡multiple¡¡singletons¡¡of¡¡the¡¡same¡¡type£»¡¡whereas¡¡with¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡shared¡¡class£»¡¡there¡¡can¡¡be¡¡only¡¡a¡¡single¡¡shared¡¡class¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Consider¡¡that¡¡locks¡¡have¡¡keys£»¡¡and¡¡sometimes¡¡a¡¡lock¡¡has¡¡a¡¡single¡¡key¡£¡¡Think¡¡of¡¡the¡¡single¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡key¡¡as¡¡a¡¡shared¡¡class¡£¡¡If¡¡that¡¡key¡¡is¡¡to¡¡open¡¡a¡¡vault£»¡¡you¡¡will¡¡most¡¡likely¡¡want¡¡only¡¡one¡¡person¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡have¡¡a¡¡key¡£¡¡But¡¡what¡¡if¡¡the¡¡key¡¡is¡¡to¡¡your¡¡house¡¡door£¿¡¡You¡¡would¡¡probably¡¡want¡¡multiple¡¡copies£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡but¡¡you¡¡will¡¡want¡¡to¡¡control¡¡who¡¡has¡¡those¡¡keys¡£¡¡So£»¡¡maybe¡¡you¡¡will¡¡have¡¡a¡¡single¡¡house¡¡key£»¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡or¡¡maybe¡¡you¡¡will¡¡have¡¡multiple¡¡house¡¡keys£»¡¡but¡¡you¡¡will¡¡always¡¡be¡¡in¡¡control¡£¡¡The¡¡house¡¡key¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡example¡¡is¡¡analogous¡¡to¡¡the¡¡use¡¡of¡¡a¡¡singleton¡£¡¡You¡¡could¡¡argue¡¡that¡¡a¡¡singleton¡¡could¡¡just¡¡as¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡well¡¡be¡¡used¡¡to¡¡open¡¡a¡¡vault£»¡¡since¡¡you¡¡can¡¡create¡¡a¡¡single¡¡key¡£¡¡But¡¡the¡¡problem¡¡with¡¡a¡¡singleton¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡is¡¡that¡¡using¡¡properly¡¡written¡¡source¡¡code£»¡¡you¡¡could¡¡instantiate¡¡a¡¡second¡¡or¡¡third¡¡instance¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡singleton¡£¡¡If¡¡you¡¡use¡¡a¡¡shared¡¡class£»¡¡then¡¡source¡¡code¡¡cannot¡¡instantiate¡¡a¡¡second¡¡instance£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡thus¡¡enforcing¡¡a¡¡certain¡¡programming¡¡style¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡347¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡2¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡AP¡¡P¡¡L¡¡I¡¡CAT¡¡I¡¡ON¡¡¡¡¡¡CO¡¡N¡¡F¡¡IG¡¡U¡¡R¡¡AT¡¡IO¡¡N¡¡¡¡¡¡A¡¡N¡¡D¡¡¡¡¡¡D¡¡Y¡¡N¡¡A¡¡M¡¡IC¡¡¡¡¡¡L¡¡O¡¡AD¡¡IN¡¡G¡¡325¡¡



¡¡¡¡¡¡¡¡¡¡Let¡¯s¡¡define¡¡the¡¡class¡¡ConfigurationLoader¡¡as¡¡a¡¡singleton£»¡¡which¡¡implies¡¡two¡¡things£º¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡The¡¡creation¡¡of¡¡a¡¡property¡¡called¡¡Instance¡¡that¡¡references¡¡a¡¡single¡¡instance¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ConfigurationLoader¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡The¡¡constructor¡¡of¡¡ConfigurationLoader¡¡as¡¡private£»¡¡implying¡¡that¡¡only¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ConfigurationLoader¡¡can¡¡instantiate¡¡an¡¡instance¡¡of¡¡ConfigurationLoader¡£¡¡This¡¡ensures¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡ConfigurationLoader¡¡has¡¡similar¡¡behavior¡¡to¡¡a¡¡shared¡¡class¡¡in¡¡that¡¡the¡¡consumer¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡cannot¡¡instantiate¡¡an¡¡instance¡¡of¡¡the¡¡type¡£¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡is¡¡the¡¡singleton¡¡code¡¡for¡¡ConfigurationLoader¡¡£¨placed¡¡in¡¡the¡¡Definitions¡¡¡¡

assembly£©¡£¡¡



Public¡¡Class¡¡ConfigurationLoader¡¡

¡¡¡¡¡¡¡¡Public¡¡Shared¡¡ReadOnly¡¡Property¡¡Instance£¨£©¡¡As¡¡ConfigurationLoader¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Get¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡ConfigurationLoader¡£_instance¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Get¡¡

¡¡¡¡¡¡¡¡End¡¡Property¡¡



¡¡¡¡¡¡¡¡Private¡¡Sub¡¡New£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_availableTypes¡¡=¡¡New¡¡Dictionary£¨Of¡¡String£»¡¡ConfigurationInfo£©£¨£©¡¡

¡¡¡¡¡¡¡¡End¡¡Sub¡¡



¡¡¡¡¡¡¡¡Private¡¡Shared¡¡_instance¡¡As¡¡ConfigurationLoader¡¡



¡¡¡¡¡¡¡¡Shared¡¡Sub¡¡New£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_instance¡¡=¡¡New¡¡ConfigurationLoader£¨£©¡¡

¡¡¡¡¡¡¡¡End¡¡Sub¡¡



¡¡¡¡¡¡¡¡¡£¡¡¡£¡¡¡£¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡singleton¡¡property¡¡¡¡Instance¡¡is¡¡declared¡¡as¡¡Shared£»¡¡allowing¡¡a¡¡reference¡¡of¡¡¡¡

ConfigurationLoader¡£Instance¡£¡¡The¡¡implementation¡¡of¡¡the¡¡shared¡¡property¡¡must¡¡reference¡¡a¡¡¡¡

shared¡¡data¡¡member£»¡¡which¡¡is¡¡the¡¡data¡¡member¡¡_instance¡¡in¡¡this¡¡example¡£¡¡The¡¡data¡¡member¡¡¡¡

_instance¡¡is¡¡instantiated¡¡by¡¡the¡¡shared¡¡constructor¡¡Shared¡¡New£¨£©¡£¡¡The¡¡instance¡¡constructor¡¡will¡¡¡¡

instantiate¡¡the¡¡Dictionary¡¡_availableTypes¡£¡¡¡¡



¡öNote¡¡¡¡The¡¡shared¡¡constructor¡¡is¡¡called¡¡before¡¡the¡¡instance¡¡constructor¡¡and¡¡therefore¡¡before¡¡any¡¡client¡¡code¡¡¡¡

has¡¡a¡¡chance¡¡to¡¡access¡¡members¡¡of¡¡the¡¡class¡£¡¡



Using¡¡the¡¡Instantiated¡¡Type¡¡



Now¡¡that¡¡we¡¯ve¡¡covered¡¡the¡¡singleton¡¡aspect£»¡¡we¡¡need¡¡to¡¡get¡¡back¡¡to¡¡the¡¡original¡¡problem¡¡of¡¡¡¡

writing¡¡the¡¡code¡¡to¡¡instantiate¡¡a¡¡type¡¡dynamically¡£¡¡The¡¡following¡¡code¡¡is¡¡used¡¡to¡¡instantiate¡¡¡¡

Impl1¡¡in¡¡the¡¡Main£¨£©¡¡method¡¡of¡¡CallRuntimeImplementation¡¯s¡¡principal¡¡module¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡348¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

326¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡2¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡A¡¡PP¡¡L¡¡I¡¡CA¡¡TI¡¡O¡¡N¡¡¡¡¡¡CO¡¡N¡¡F¡¡I¡¡G¡¡U¡¡R¡¡AT¡¡IO¡¡N¡¡¡¡¡¡AN¡¡D¡¡¡¡¡¡D¡¡Y¡¡N¡¡A¡¡M¡¡I¡¡C¡¡¡¡L¡¡O¡¡AD¡¡I¡¡N¡¡G¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ConfigurationLoader¡£Instance¡£Load£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡definition¡¡as¡¡IDefinition¡¡=¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ConfigurationLoader¡£Instance¡£Instantiate£¨Of¡¡IDefinition£©£¨¡¨Impl1¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨definition¡£TranslateWord£¨¡¨hello¡¨£©£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡You¡¡might¡¡get¡¡errors¡¡running¡¡the¡¡code¡£¡¡If¡¡you¡¡do£»¡¡it¡¡is¡¡because¡¡the¡¡assemblies¡¡are¡¡not¡¡in¡¡the¡¡same¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡path¡¡and¡¡the¡¡dynamic¡¡loading¡¡methods¡¡cannot¡¡find¡¡the¡¡assemblies¡£¡¡Solve¡¡this¡¡by¡¡copying¡¡all¡¡of¡¡the¡¡assemblies¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡into¡¡a¡¡single¡¡directory¡¡and¡¡running¡¡the¡¡code¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡first¡¡line¡¡is¡¡used¡¡to¡¡retrieve¡¡the¡¡assembly¡¡and¡¡type¡¡information¡¡from¡¡the¡¡configuration¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡file¡£¡¡The¡¡second¡¡line¡¡is¡¡used¡¡to¡¡instantiate¡¡Impl1¡¡and¡¡then¡¡cast¡¡¡¡Implementations1¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implementation¡¡to¡¡type¡¡IDefinition¡£¡¡The¡¡cast¡¡will¡¡work¡¡because¡¡the¡¡IDefinition¡¡interface¡¡has¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡been¡¡implemented¡¡by¡¡Implementations1¡£Implementation¡£¡¡The¡¡assigned¡¡variable¡¡definition¡¡will¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡reference¡¡a¡¡valid¡¡object¡¡instance¡¡that¡¡implements¡¡IDefinition¡¡and¡¡the¡¡method¡¡TranslateWord£¨£©¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡At¡¡this¡¡point£»¡¡we¡¡need¡¡to¡¡step¡¡back¡¡and¡¡reflect¡¡on¡¡what¡¡has¡¡occurred¡£¡¡We¡¡have¡¡defined¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡within¡¡a¡¡configuration¡¡file¡¡the¡¡location¡¡of¡¡a¡¡type¡£¡¡Some¡¡source¡¡code¡¡in¡¡the¡¡application¡¡read¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡configuration¡¡file¡¡at¡¡runtime¡¡and¡¡stored¡¡the¡¡available¡¡types¡£¡¡The¡¡calling¡¡code¡¡knew¡¡about¡¡only¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡abstract¡¡type¡¡made¡¡available¡¡under¡¡the¡¡label¡¡Impl1¡¡and¡¡knew¡¡it¡¡implemented¡¡the¡¡interface¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡IDefinition¡£¡¡Then£»¡¡using¡¡some¡¡¡¡magic¡¡involving¡¡dynamic¡¡techniques£»¡¡the¡¡type¡¯s¡¡assembly¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡is¡¡loaded¡¡and¡¡instantiated¡£¡¡This¡¡process¡¡is¡¡unique¡¡because¡¡an¡¡administrator¡¡has¡¡the¡¡ability¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡update¡¡where¡¡and¡¡what¡¡type¡¡should¡¡be¡¡instantiated¡¡and¡¡called£»¡¡without¡¡needing¡¡to¡¡repile¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡or¡¡update¡¡the¡¡infrastructure¡£¡¡That¡¡flexibility¡¡makes¡¡it¡¡much¡¡simpler¡¡for¡¡you¡¡to¡¡update¡¡function

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ality¡¡without¡¡having¡¡to¡¡update¡¡the¡¡caller¡¡of¡¡the¡¡functionality¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡The¡¡ability¡¡to¡¡dynamically¡¡update¡¡the¡¡functionality¡¡is¡¡of¡¡benefit¡¡to¡¡the¡¡administrator¡¡of¡¡the¡¡application¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡There¡¡is¡¡minimal¡¡benefit¡¡to¡¡the¡¡developer£»¡¡because¡¡the¡¡developer¡¡has¡¡already¡¡converted¡¡the¡¡architecture¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡use¡¡ponents¡£¡¡In¡¡general£»¡¡developers¡¡consider¡¡this¡¡approach¡¡to¡¡ponents¡¡as¡¡building¡¡a¡¡plug¡­in¡¡architecture¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Enhancing¡¡the¡¡Configuration¡¡File¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡configuration¡¡file¡¡is¡¡a¡¡bit¡¡of¡¡a¡¡clumsy¡¡definition¡¡because¡¡all¡¡of¡¡the¡¡available¡¡types¡¡are¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡stored¡¡in¡¡a¡¡single¡¡key/value¡¡pair¡£¡¡It¡¡would¡¡be¡¡preferable¡¡to¡¡be¡¡able¡¡to¡¡define¡¡custom¡¡items¡¡in¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡configuration¡¡file£»¡¡as¡¡follows£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡approach¡¡is¡¡preferable¡¡because¡¡it¡¡is¡¡easier¡¡to¡¡read¡¡and¡¡understand£»¡¡thus¡¡reducing¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡chances¡¡that¡¡you¡¡will¡¡have¡¡an¡¡error¡£¡¡Additionally£»¡¡because¡¡the¡¡various¡¡identifiers¡¡are¡¡broken¡¡up£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡you¡¡don¡¯t¡¡need¡¡to¡¡build¡¡a¡¡lengthy¡¡single¡­line¡¡string¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡349¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡2¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡AP¡¡P¡¡L¡¡I¡¡CAT¡¡I¡¡ON¡¡¡¡¡¡CO¡¡N¡¡F¡¡IG¡¡U¡¡R¡¡AT¡¡IO¡¡N¡¡¡¡¡¡A¡¡N¡¡D¡¡¡¡¡¡D¡¡Y¡¡N¡¡A¡¡M¡¡IC¡¡¡¡¡¡L¡¡O¡¡AD¡¡IN¡¡G¡¡327¡¡



¡öNote¡¡¡¡For¡¡simplicity£»¡¡we¡¡will¡¡have¡¡only¡¡a¡¡single¡¡dynamic¡¡type£»¡¡represented¡¡by¡¡the¡¡¡¡XML¡¡element¡£¡¡¡¡

In¡¡a¡¡plete¡¡solution£»¡¡you¡¡would¡¡use¡¡the¡¡same¡¡approach¡¡with¡¡different¡¡interfaces¡¡and¡¡types¡£¡¡



¡¡¡¡¡¡¡¡¡¡If¡¡you¡¡were¡¡to¡¡add¡¡the¡¡sample¡¡XML¡¡into¡¡the¡¡configuration¡¡file¡¡and¡¡run¡¡the¡¡¡¡application£»¡¡¡¡

you¡¡would¡¡get¡¡a¡¡configuration¡¡initialization¡¡failure¡£¡¡That¡¯s¡¡because¡¡the¡¡XML¡¡node¡¡¡¡is¡¡not¡¡a¡¡¡¡

standard¡¡configuration¡¡item¡¡and¡¡thus¡¡needs¡¡custom¡¡parsing¡£¡¡And¡¡when¡¡you¡¡want¡¡custom¡¡parsing£»¡¡¡¡

you¡¡need¡¡to¡¡tell¡¡the¡¡¡¡configuration¡¡infrastructure¡¡what¡¡code¡¡to¡¡execute¡£¡¡The¡¡following¡¡is¡¡¡¡

the¡¡plete¡¡¡¡configuration¡¡file¡¡with¡¡custom¡¡processing¡¡tags¡£¡¡



¡¡

¡¡

¡¡¡¡¡¡

¡¡¡¡¡¡¡¡¡¡

¡¡¡¡¡¡

¡¡¡¡¡¡

¡¡¡¡¡¡¡¡
·µ»ØĿ¼ ÉÏÒ»Ò³ ÏÂÒ»Ò³ »Øµ½¶¥²¿ ÔÞ£¨11£© ²È£¨11£©
¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿!
ÎÂÜ°Ìáʾ£º ο´Ð¡ËµµÄͬʱ·¢±íÆÀÂÛ£¬Ëµ³ö×Ô¼ºµÄ¿´·¨ºÍÆäËüС»ï°éÃÇ·ÖÏíÒ²²»´íŶ£¡·¢±íÊéÆÀ»¹¿ÉÒÔ»ñµÃ»ý·ÖºÍ¾­Ñé½±Àø£¬ÈÏÕæдԭ´´ÊéÆÀ ±»²ÉÄÉΪ¾«ÆÀ¿ÉÒÔ»ñµÃ´óÁ¿½ð±Ò¡¢»ý·ÖºÍ¾­Ñé½±ÀøŶ£¡