Read .NET configuration from database

前端 未结 4 2083
难免孤独
难免孤独 2020-12-18 22:20

The .NET 2.0 and up configuration system is quite powerful and extensible - as long as you don\'t want to change the fact it all comes from XML files in the filesystem.

4条回答
  •  暖寄归人
    2020-12-18 23:12

    You can try Cinchoo framework for your needs.

    It supports reading and writing configuration entries to File, Registry, INI, Database etc.

    Here is the simple way to define and use the configuration object using Cinchoo framework

    namespace HelloWorld
    {
        #region NameSpaces
    
        using System;
        using Cinchoo.Core.Configuration;
    
        #endregion NameSpaces
    
        [ChoConfigurationSection("sample")]
        public class SampleConfigSection : ChoConfigurableObject
        {
            [ChoPropertyInfo("name", DefaultValue="Mark")]
            public string Name;
    
            [ChoPropertyInfo("message", DefaultValue="Hello World!")]
            public string Message;
        }
    
        static void Main(string[] args)
        {
            SampleConfigSection sampleConfigSection = new SampleConfigSection();
            Console.WriteLine(sampleConfigSection.ToString());
        }
    
    }
    

    Very first time, when you run the application, Cinchoo framework automatically generates the configuration section as below. Then onwards, you can control them either through configuration source or by code.

    
    
      
        

    Try it!

提交回复
热议问题