■ 애플리케이션 구성 파일 변경하기

----------------------------------------------------------------------------------------------------


TestProject.zip


Program.cs

 

 

using System;

using System.Configuration;

 

namespace TestProject

{

    /// <summary>

    /// 프로그램

    /// </summary>

    class Program

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Static

        //////////////////////////////////////////////////////////////////////////////// Private

 

        #region 프로그램 실행하기 - Main()

 

        /// <summary>

        /// 프로그램 실행하기

        /// </summary>

        private static void Main()

        {

            Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration

            (

                new ExeConfigurationFileMap { ExeConfigFilename = "AppAnother.config" },

                ConfigurationUserLevel.None

            );

 

            foreach(KeyValueConfigurationElement element in configuration.AppSettings.Settings)

            {

                string value = ConfigurationManager.AppSettings[element.Key];

 

                if(value == null)

                {

                    ConfigurationManager.AppSettings.Set(element.Key, element.Value);

                }

                else

                {

                    ConfigurationManager.AppSettings[element.Key] = element.Value;

                }

            }

 

            Console.WriteLine("Language : {0}", ConfigurationManager.AppSettings["Language"]);

            Console.WriteLine("Version  : {0}", ConfigurationManager.AppSettings["Version" ]);

        }

 

        #endregion

    }

}

 

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요