Customize some configuration information in APP. config

Source: Internet
Author: User

We thought of deserializing XML. We can get this object.

 


[Serializable ()]
[Xmlroot ("fetcherconfig")]
Public class fetcherconfiguration
{
/** // Some attributes

Public static fetcherconfiguration getconfig ()
{
If (instance _ = NULL)
{
Instance _ = (fetcherconfiguration) configurationsettings. getconfig ("fetcherconfig ");
}
Return instance _;
}

}

Where does the XML information come from? We put it in APP. config, so we need the following handler.

Public class fetcherconfigserializersectionhandler: iconfigurationsectionhandler
{
Iconfigurationsectionhandler members # region iconfigurationsectionhandler members

Public object create (Object parent, object configcontext, system. xml. xmlnode Section)
{
Xmlserializer SER = new xmlserializer (typeof (fetcherconfiguration ));
Return Ser. deserialize (New xmlnodereader (section ));
}

# Endregion
}

Configuration
We need to add our <configsections>
<Section name = "configuration section name xmlroot name" type = "class full name, class library name"/>
Next we can put some information
<Configuration>
You don't know what to put. You can serialize the class you need first. You can simply copy the information.

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.