°Ë±¦Êé¿â > ÎÄѧÆäËûµç×ÓÊé > VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ) >

µÚ94²¿·Ö

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

С˵£º VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ) ×ÖÊý£º ÿҳ4000×Ö

°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡




¡¡¡¡¡¡

¡¡¡¡¡¡

¡¡¡¡¡¡¡¡¡¡

¡¡¡¡¡¡

¡¡¡¡¡¡



¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡bolded¡¡section¡¡represents¡¡a¡¡new¡¡part¡¡of¡¡the¡¡configuration¡¡file¡¡that¡¡could¡¡be¡¡called¡¡¡¡

¡°configuring¡¡the¡¡configuration¡£¡±¡¡Any¡¡XML¡¡node¡¡that¡¡is¡¡within¡¡the¡¡¡¡section¡¡is¡¡¡¡

used¡¡to¡¡customize¡¡the¡¡configuration¡­parsing¡¡infrastructure¡£¡¡In¡¡the¡¡example£»¡¡the¡¡XML¡¡node¡¡¡¡

¡¡has¡¡two¡¡attributes¡¡that¡¡refer¡¡to¡¡what¡¡the¡¡configuration¡¡infrastructure¡¡should¡¡do¡¡¡¡

when¡¡it¡¡encounters¡¡a¡¡specific¡¡XML¡¡node¡£¡¡The¡¡attribute¡¡¡¡name¡¡specifies¡¡the¡¡name¡¡of¡¡the¡¡XML¡¡¡¡

node£»¡¡and¡¡the¡¡attribute¡¡type¡¡references¡¡a¡¡type¡¡£¨Definitions¡£LoaderSection£©¡¡and¡¡assembly¡¡¡¡

£¨Definitions£©¡¡that¡¡will¡¡process¡¡the¡¡XML¡¡node¡£¡¡

¡¡¡¡¡¡¡¡¡¡Step¡¡back¡¡and¡¡think¡¡about¡¡what¡¡is¡¡happening¡¡here¡£¡¡The¡¡XML¡¡node¡¡¡¡is¡¡used¡¡to¡¡¡¡

configure¡¡the¡¡configuration¡¡processor¡¡using¡¡dynamically¡¡loaded¡¡types¡£¡¡This¡¡demonstrates¡¡that¡¡¡¡

the¡¡process¡¡of¡¡dynamically¡¡loading¡¡and¡¡executing¡¡pieces¡¡of¡¡code¡¡is¡¡not¡¡rocket¡¡science£»¡¡but¡¡a¡¡¡¡

daily¡¡part¡¡of¡¡developing¡¡ponents¡¡in¡¡¡£¡¡



Marshaling¡¡the¡¡Configuration¡¡File¡¡Data¡¡



When¡¡you¡¡want¡¡to¡¡use¡¡a¡¡custom¡¡node¡¡in¡¡a¡¡configuration¡¡file£»¡¡you¡¡need¡¡to¡¡implement¡¡a¡¡class¡¡that¡¡¡¡

subclasses¡¡System¡£Configuration¡£ConfigurationSection¡£¡¡The¡¡purpose¡¡of¡¡the¡¡custom¡¡class¡¡is¡¡to¡¡¡¡

process¡¡and¡¡structure¡¡the¡¡data¡¡in¡¡the¡¡configuration¡¡file¡¡into¡¡something¡¡that¡¡the¡¡application¡¡can¡¡¡¡

manipulate¡£¡¡In¡¡other¡¡words£»¡¡we¡¡are¡¡marshaling¡¡the¡¡data¡¡from¡¡the¡¡configuration¡¡file¡¡to¡¡the¡¡¡¡¡¡

environment¡£¡¡Here¡¯s¡¡the¡¡start¡¡of¡¡our¡¡class£»¡¡which¡¡belongs¡¡in¡¡the¡¡Definitions¡¡assembly£º¡¡



Public¡¡Class¡¡LoaderSection¡¡

¡¡¡¡¡¡¡¡Inherits¡¡ConfigurationSection¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡350¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

328¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡¡¡infrastructure¡¡helps¡¡you¡¡implement¡¡the¡¡marshaling¡¡routines¡¡by¡¡providing¡¡class¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡types¡¡that¡¡allow¡¡you¡¡to¡¡explicitly¡¡associate¡¡an¡¡XML¡¡attribute¡¡or¡¡keyword¡¡with¡¡some¡¡variable¡£¡¡For¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡example£»¡¡suppose¡¡you¡¡want¡¡to¡¡cross¡­reference¡¡the¡¡XML¡¡attribute¡¡easyname¡¡with¡¡a¡¡¡¡type¡£¡¡To¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡do¡¡so£»¡¡first¡¡define¡¡the¡¡nature¡¡and¡¡type¡¡of¡¡the¡¡property¡¡using¡¡the¡¡type¡¡ConfigurationProperty¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨this¡¡code¡¡goes¡¡in¡¡the¡¡LoaderSection¡¡class£©£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡_propEasyName¡¡As¡¡ConfigurationProperty¡¡=¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡New¡¡ConfigurationProperty£¨¡¨easyname¡¨£»¡¡GetType£¨String£©£»¡¡Nothing£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ConfigurationPropertyOptions¡£IsRequired£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡example¡¡uses¡¡the¡¡ConfigurationProperty¡¡constructor¡¡that¡¡has¡¡four¡¡parameters£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡¡¨easyname¡¨£º¡¡Identifies¡¡the¡¡XML¡¡attribute¡¡identifier¡¡that¡¡will¡¡be¡¡used¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡GetType£¨String£©£º¡¡Identifies¡¡the¡¡type¡¡of¡¡the¡¡attribute£»¡¡which¡¡could¡¡also¡¡include¡¡Double¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡Integer¡¡to¡¡indicate¡¡a¡¡number¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Nothing£º¡¡Identifies¡¡the¡¡default¡¡value¡¡of¡¡the¡¡attribute¡¡if¡¡the¡¡attribute¡¡is¡¡not¡¡present¡¡in¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡XML¡¡configuration¡¡file¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡ConfigurationPropertyOptions¡£IsRequired£º¡¡Identifies¡¡some¡¡characteristics¡¡of¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡attribute£»¡¡in¡¡the¡¡case¡¡of¡¡this¡¡example£»¡¡the¡¡attribute¡¡is¡¡required¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡There¡¡are¡¡multiple¡¡constructors¡¡for¡¡ConfigurationProperty¡£¡¡For¡¡more¡¡information£»¡¡check¡¡out¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡MSDN¡¡documentation¡¡£¨http£º//msdn2¡£microsoft¡£/en¡­us/library/system¡£configuration¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡configurationproperty¡£configurationproperty¡£aspx£©¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Once¡¡you¡¡have¡¡defined¡¡a¡¡property£»¡¡you¡¡need¡¡to¡¡cross¡­reference¡¡it¡¡with¡¡a¡¡property¡¡and¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡base¡¡class¡¡ConfigurationSection¡¡£¨again£»¡¡this¡¡code¡¡goes¡¡in¡¡the¡¡¡¡LoaderSection¡¡class£©£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡ReadOnly¡¡Property¡¡EasyName£¨£©¡¡As¡¡String¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡CStr£¨MyBase¡£Item£¨_propEasyName£©£©¡¡

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

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Whenever¡¡you¡¡reference¡¡the¡¡property¡¡EasyName£»¡¡the¡¡attributes¡¡associated¡¡with¡¡the¡¡property¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡provide¡¡a¡¡cross¡­reference¡¡with¡¡the¡¡configuration¡¡file¡£¡¡Whenever¡¡the¡¡property¡¡is¡¡called£»¡¡the¡¡base¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡indexer¡¡with¡¡data¡¡member¡¡that¡¡references¡¡ConfigurationProperty¡¡is¡¡called¡¡and¡¡marshals¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡data¡¡from¡¡the¡¡configuration¡¡file¡¡to¡¡the¡¡¡¡type¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡plete¡¡implementation¡¡used¡¡to¡¡process¡¡the¡¡XML¡¡node¡¡¡¡is¡¡as¡¡follows¡¡£¨added¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡the¡¡Definitions¡¡assembly£©£º¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡351¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡329¡¡



Imports¡¡System¡£Configuration¡¡



Public¡¡Class¡¡LoaderSection¡¡

¡¡¡¡¡¡¡¡Inherits¡¡ConfigurationSection¡¡



¡¡¡¡¡¡¡¡Private¡¡Shared¡¡_propAssemblyName¡¡As¡¡ConfigurationProperty¡¡=¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡New¡¡ConfigurationProperty£¨¡¨assemblyname¡¨£»¡¡GetType£¨String£©£»¡¡Nothing£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ConfigurationPropertyOptions¡£IsRequired£©¡¡

¡¡¡¡¡¡¡¡Private¡¡Shared¡¡_propEasyName¡¡As¡¡ConfigurationProperty¡¡=¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡New¡¡ConfigurationProperty£¨¡¨easyname¡¨£»¡¡GetType£¨String£©£»¡¡Nothing£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ConfigurationPropertyOptions¡£IsRequired£©¡¡

¡¡¡¡¡¡¡¡Private¡¡Shared¡¡_properties¡¡As¡¡ConfigurationPropertyCollection¡¡=¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡New¡¡ConfigurationPropertyCollection£¨£©¡¡

¡¡¡¡¡¡¡¡Private¡¡Shared¡¡_propTypeName¡¡As¡¡ConfigurationProperty¡¡=¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡New¡¡ConfigurationProperty£¨¡¨typename¡¨£»¡¡GetType£¨String£©£»¡¡Nothing£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ConfigurationPropertyOptions¡£IsRequired£©¡¡



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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_properties¡£Add£¨_propAssemblyName£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_properties¡£Add£¨_propEasyName£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_properties¡£Add£¨_propTypeName£©¡¡

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



¡¡¡¡¡¡¡¡¡¡_¡¡

¡¡¡¡¡¡¡¡Public¡¡ReadOnly¡¡Property¡¡AssemblyName£¨£©¡¡As¡¡String¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡CStr£¨MyBase¡£Item£¨_propAssemblyName£©£©¡¡

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

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



¡¡¡¡¡¡¡¡¡¡_¡¡

¡¡¡¡¡¡¡¡Public¡¡ReadOnly¡¡Property¡¡EasyName£¨£©¡¡As¡¡String¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡CStr£¨MyBase¡£Item£¨_propEasyName£©£©¡¡

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

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



¡¡¡¡¡¡¡¡¡¡_¡¡

¡¡¡¡¡¡¡¡Public¡¡ReadOnly¡¡Property¡¡TypeName£¨£©¡¡As¡¡String¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡CStr£¨MyBase¡£Item£¨_propTypeName£©£©¡¡

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

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

End¡¡Class¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡352¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

330¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡¡¡LoaderSection¡¡class¡¡does¡¡two¡¡jobs£º¡¡it¡¡tells¡¡the¡¡underlying¡¡configuration¡¡infrastructure¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡what¡¡¡¡LoaderSection¡¡is¡¡interested¡¡in£»¡¡and¡¡it¡¡provides¡¡an¡¡easy¡­to¡­use¡¡API¡¡to¡¡the¡¡configuration¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡data¡£¡¡The¡¡first¡¡job¡¡is¡¡nice¡¡to¡¡have¡¡done£»¡¡but¡¡the¡¡second¡¡is¡¡absolutely¡¡essential¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡understand¡¡what¡¡happens£»¡¡let¡¯s¡¡see¡¡an¡¡example¡¡of¡¡retrieving¡¡the¡¡values¡¡from¡¡a¡¡configu

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ration¡¡file¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Reading¡¡the¡¡Enhanced¡¡Configuration¡¡File¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡As¡¡you¡¯ve¡¡seen£»¡¡the¡¡¡¡element¡¡declares¡¡a¡¡custom¡¡XML¡¡node¡¡that£»¡¡when¡¡encoun

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tered£»¡¡instantiates¡¡a¡¡specific¡¡type¡ª¡¡LoaderSection¡¡is¡¡instantiated¡¡in¡¡this¡¡example¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡values¡¡are¡¡retrieved¡¡from¡¡the¡¡custom¡¡configuration¡¡as¡¡follows£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡The¡¡configuration¡¡infrastructure¡¡reads¡¡the¡¡various¡¡attributes£»¡¡such¡¡as¡¡¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡The¡¡configuration¡¡infrastructure¡¡does¡¡a¡¡cross¡­reference¡¡of¡¡which¡¡attributes¡¡exist¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡if¡¡they¡¡are¡¡required¡£¡¡Think¡¡of¡¡this¡¡step¡¡as¡¡the¡¡bookkeeping¡¡of¡¡the¡¡custom¡¡configuration¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡information¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡The¡¡configuration¡¡infrastructure¡¡waits¡¡for¡¡the¡¡application¡¡code¡¡to¡¡call¡¡the¡¡properties¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡EasyName£»¡¡TypeName£»¡¡or¡¡AssemblyName¡£¡¡In¡¡the¡¡implementation¡¡of¡¡the¡¡individual¡¡properties£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡MyBase¡¡indexer¡¡£¨such¡¡as¡¡MyBase¡£Item£¨_propTypeName£©¡¡from¡¡¡¡LoaderSection¡£TypeName£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡is¡¡referenced£»¡¡and¡¡the¡¡value¡¡of¡¡the¡¡configuration¡¡item¡¡is¡¡retrieved¡¡using¡¡the¡¡property¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡descriptors¡¡declared¡¡as¡¡shared¡¡members¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡We¡¡can¡¡use¡¡the¡¡following¡¡code¡¡to¡¡read¡¡the¡¡custom¡¡configuration¡¡item¡¡£¨added¡¡to¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Definitions¡¡assembly£©¡£¡¡This¡¡code¡¡is¡¡an¡¡example¡¡of¡¡replacing¡¡the¡¡previously¡¡declared¡¡¡¡Load£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡functionality¡£¡¡



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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡loader¡¡As¡¡LoaderSection¡¡=¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CType£¨ConfigurationManager¡£GetSection£¨¡¨loader¡¨£©£»¡¡LoaderSection£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡loader¡¡IsNot¡¡Nothing¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡configInfo¡¡As¡¡ConfigurationInfo¡¡=¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡New¡¡ConfigurationInfo£¨£©¡¡With¡¡£û¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£EasyName¡¡=¡¡loader¡£EasyName£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£TypeName¡¡=¡¡loader¡£TypeName£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£AssemblyName¡¡=¡¡loader¡£AssemblyName£ý¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_availableTypes¡£Add£¨loader¡£EasyName£»¡¡configInfo£©¡¡



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

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡only¡¡major¡¡difference¡¡between¡¡this¡¡code¡¡and¡¡the¡¡previous¡¡¡¡Load£¨£©¡¡code¡¡is¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ConfigurationManager¡¡reference¡£¡¡In¡¡the¡¡previous¡¡¡¡Load£¨£©¡¡implementation£»¡¡it¡¡was¡¡assumed¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡all¡¡configuration¡¡settings¡¡were¡¡stored¡¡in¡¡the¡¡¡¡section¡£¡¡This¡¡time£»¡¡we¡¡retrieve¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡section£»¡¡which¡¡is¡¡defined¡¡to¡¡be¡¡t

·µ»ØĿ¼ ÉÏÒ»Ò³ ÏÂÒ»Ò³ »Øµ½¶¥²¿ ÔÞ£¨0£© ²È£¨1£©

Äã¿ÉÄÜϲ»¶µÄ