| 以下为引用的内容: <sectionGroup name="CustomGroup"> <section name="Custom1" type="System.Configuration.NameValueSectionHandler"/> <section name="Custom2" type="System.Configuration.NameValueSectionHandler"/> </sectionGroup> |
| 以下为引用的内容: <MyCustomSection> <add key="key1" value="value1"/> <add key="key2" value="value2"/> </MyCustomSection> |
| [color=#ff0000]以下为引用的内容: . . . <section name="MySingleTagSection" type="System.Configuration.SingleTagSectionHandler"/> . . . <MySingleTagSection setting1="value1" setting2="value2" setting3="value3"/> . . . DictionarySectionHandler与NameValueSectionHandler相似,但前者返回hashtable,后者返回NameValueCollection。当访问大量配置值时,hashtable要快于NameValueCollectio。DictionarySectionHandler与NameValueSectionHandler的构造方式相同,如下例: . . . <section name="MyDictionarySection" type="System.Configuration.DictionarySectionHandler"/> . . . <MyDictionarySection> <add key="key1" value="value1"/> </MyDictionarySection> . . . |
| 以下为引用的内容: <CustomGroup> <Custom1> <add key="key1" value="value1"/> </Custom1> <Custom2> <add key="key1" value="value1"/> </Custom2> </CustomGroup> |
| 以下为引用的内容: System.Collections.IDictionary stsh = (System.Collections.IDictionary) System.Configuration.ConfigurationSettings.GetConfig("MySingleTagSection"); System.Collections.Specialized.NameValueCollection nvsh = (System.Collections.Specialized.NameValueCollection) System.Configuration.ConfigurationSettings.GetConfig("MyNameValueSection"); System.Collections.Hashtable dsh = (System.Collections.Hashtable) System.Configuration.ConfigurationSettings.GetConfig("MyDictionarySection"); System.Collections.Specialized.NameValueCollection sgnvsh = (System.Collections.Specialized.NameValueCollection) System.Configuration.ConfigurationSettings.GetConfig("MySectionGroup/MySection 1"); System.Diagnostics.Debug.WriteLine((string)stsh["sample1"]); System.Diagnostics.Debug.WriteLine((string)nvsh["key1"]); System.Diagnostics.Debug.WriteLine((string)dsh["key1"]); System.Diagnostics.Debug.WriteLine((string)sgnvsh["key1"]); |
| 以下为引用的内容: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="MySingleTagSection" type="System.Configuration.SingleTagSectionHandler"/> <section name="MyDictionarySection" type="System.Configuration.DictionarySectionHandler"/> <section name="MyNameValueSection" type="System.Configuration.NameValueSectionHandler"/> <sectionGroup name="MySectionGroup"> <section name="MySection1" type="System.Configuration.NameValueSectionHandler"/> <section name="MySection2" type="System.Configuration.NameValueSectionHandler"/> </sectionGroup> </configSections> <MySingleTagSection sample1="value1" sample2="value2" sample3="value3"/> <MyDictionarySection> <add key="key1" value="value1"/> <add key="key2" value="value2"/> </MyDictionarySection> <MyNameValueSection> <add key="key1" value="value1"/> <add key="key2" value="value2"/> </MyNameValueSection> <MySectionGroup> <MySection1> <add key="key1" value="value1"/> <add key="key2" value="value2"/> </MySection1> <MySection2> <add key="key1" value="value1"/> <add key="key2" value="value2"/> </MySection2> </MySectionGroup> </configuration> |