Summary review about Problem.Design.Solution 2

<!-- add on 07/06/04 -->


 


1.  Customize configuration section in Web.Config and handle web events.
        <configSections>
      <section name="theBeerHouse"
         type="MB.TheBeerHouse.TheBeerHouseSection, __code"/>
   </configSections>

<theBeerHouse defaultConnectionStringName="LocalSqlServer">
      <contactForm mailTo="thebeerhouse@wrox.com"/>
   </theBeerHouse>

      Specify the name of your customized section in Web.Config file, the content of 'type' stands for the classname, which will be used to handle your customized section.

      Create a specific class to handle this(its name needs to be same as the type you specified in Web.Config file), inheriting from ConfigurationSection. Use the [ConfigurationProperty("xxxx", DefaultValue="xxxxxx")] to bind the property to target node.

public class TheBeerHouseSection : ConfigurationSection
   {
      [ConfigurationProperty("defaultConnectionStringName",
         DefaultValue = "LocalSqlServer")]
      public string DefaultConnectionStringName
      {
         get { return (string)base["defaultConnectionStringName"]; }
         set { base["connectionStdefaultConnectionStringNameringName"] = value; }
      }
      [ConfigurationProperty("contactForm", IsRequired=true)]
      public ContactFormElement ContactForm
      {
         get { return (ContactFormElement) base["contactForm"]; }
      }
        
public class ContactFormElement : ConfigurationElement
     {
        ..........

     }



      public readonly static TheBeerHouseSection Settings =
         (TheBeerHouseSection)WebConfigurationManager.GetSection("theBeerHouse");

     Note that you need to convert the type of your customized config section in order to create a reference to use.

   



2.  Two approaches to  loop through Cache
     Loop Recursively by using the IDictionaryEnumerator && Cache.GetEnumerator()
     IDictionaryEnumerator enumerator = BizObject.Cache.GetEnumerator();
         while (enumerator.MoveNext())
         {
            if (enumerator.Key.ToString().ToLower().StartsWith(prefix))
         }

      Loop Recursively by using the DictionaryEntry
      foreach   (DictionaryEntry   de   in   Cache)
         {
         }




 
posted @ 2007-06-04 16:43  眼里进了砂  阅读(263)  评论(0编辑  收藏  举报