. 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.