. Net -- use the. net built-in handler to process the User-Defined node Demo

Source: Internet
Author: User

. Net -- use the. net built-in handler to process the User-Defined node Demo

 

In. net, because different nodes correspond to classes to process them ,. Net has some built-in classes for our convenience, so that we do not have to define classes to process custom nodes when reading the configuration file.

 

The following is a configuration file:

 

 

 

The node name is mailServeraddress, which has three attributes. SingleTagSectionHandler is defined in the section to process this node.

 

 

Namespace custom node and built-in handler {class Program {static void Main (string [] args) {ExampleSingleTagSectionHandler ();} private static void ExampleSingleTagSectionHandler () {// SingleTagSectionHandler returns all attributes of the node, hashtable mailServer = (Hashtable) ConfigurationManager, in the form of Hashtable. getSection (mailServeraddress); // call GetSection to return 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, call GetSection to forcibly convert it to hashtable, and then you can read the node attribute values in the form of key-value.

 

In. net, apart from the type in the above example, we can also use other built-in types to process custom nodes.

 

 

 

 

 

 

 

 

 

 

 

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.