. net--using. Net built-in handlers to handle custom nodes demo

Source: Internet
Author: User
in. NET, because a different node corresponds to a class to handle it. NET inside for convenience, has built up some classes for us to use, so that when we read the configuration file, we do not have to define the class to handle their own defined custom nodes.

below we have written a configuration file:

<?xml version= "1.0" encoding= "Utf-8"?><configuration>  <configSections>    <!-- Use ignoresection to handle custom nodes-    <!--<section name= "mailserveraddress" type= " System.Configuration.IgnoreSection, System.Configuration, version=4.0.0.0, Culture=neutral, publickeytoken= B03F5F7F11D50A3A "allowlocation=" false "restartonexternalchanges=" true "/>-->    <section name=" Mailserveraddress "type=" System.Configuration.SingleTagSectionHandler "/>        <!--Note that Specifies that the handler configuration file is written in front of the custom profile-  </configSections>      <mailserveraddress address= " Mail.tracefact.net "Username=" LHC "password=" 124324 "/> </configuration>

The node name is: Mailserveraddress, with three attributes, defined in section SingleTagSectionHandler to handle this node.

namespace custom node and built-in handler {    class program    {        static void Main (string[] args)        {            Examplesingletagsectionhandler ();        }        private static void Examplesingletagsectionhandler () {            //singletagsectionhandler returns all the properties            of a node in the form of Hashtable Hashtable mailserver = (Hashtable) configurationmanager.getsection ("mailserveraddress");// Calling GetSection returns a hashtable            string address = mailserver["Address". ToString ();            String username = mailserver["username"]. ToString ();            String PassWord = mailserver["PassWord"]. ToString ();            Console.WriteLine (address+ "----" +username+ "------" +password);}}}    

After the configuration file is written, after calling GetSection strong Hashtable, you can read the attribute value of the node in the form of Key--value.

In. NET, in addition to this type in the example above, we can also use other built-in type to handle the custom node.


The above is. net--use. Net built-in handlers to handle the contents of your custom node demo, and more about topic.alibabacloud.com (www.php.cn)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.