Overview
1. When developing programs, we often need to use the following two basic modules:
1> set basic program parameters, such as paging parameters and mail parameters;
2> in table-based development, some judgment logic is placed in table data;
2. In these two basic scenarios, we have the following requirements:
1> Centralized Management;
2> to be configurable, modify the parameters without restarting the system;
3> easy to use.
Main functions of the program
1> set basic program parameters, such as paging parameters and mail parameters;
---- Automatically add the configuration information in XML to the corresponding object.
2> in table-based development, some judgment logic is placed in table data;
---- Automatically load the Dctionary data in XML to the corresponding entity. However, this method needs to be further optimized. Currently, it only supports loading Dictionary and more complex structures.
Main Code
1. First define and reference the entity in the code.
Example
Dictionary<, > Dictionary<, >
2. Define the corresponding XML file. The basic configuration information of the program is configured in AppSettings.
Under the node.
3. Finally, a piece of XML loading code is required to load the XML configuration information in 2 to the object in 1.
Dictionary<, Dictionary<, >> DictAppSettings = Dictionary<, Dictionary<, >>= System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory.ToString(), LoadSettings( XmlNode dictRootNode = FileHelper.GetXMLNode(path, (XmlNode dictType <, > dict = Dictionary<, > (XmlNode dictItem ].Value.Trim(), dictItem.Attributes[ serializer = jAppSetting = serializer.Serialize(DictAppSettings[ jDict = json = .Format(, jAppSetting.Remove(jAppSetting.Length - ), jDict.Remove(, = serializer.Deserialize<AppSetting> CacheRemovedCallback( key, xmlFilePath = ( System.Threading.Thread.Sleep( XmlNode GetXMLNode( path, = CacheDependencyFile(=
Final Effect
1. When the program runs for the first time, the corresponding configuration information is output.
2. When you modify some parameters, you can obtain the latest information without restarting them. Note: After modifying the parameters for 3 seconds, refresh the page.
Download complete code