posted by 방랑군 2009. 9. 23. 13:07




App.config

<?xml version="1.0" encoding="utf-8" ?>

<configuration>


  <configSections>

    <section name="unity" type="Console_Config_User.UserInfo,Console_Config_User" />

  </configSections>


  <unity>

    <NAME>황승재</NAME>

    <ADDRESS>염창동</ADDRESS>

    <HP>016-647-0678</HP>

  </unity>

</configuration>


Console_Config_User.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;


using System.Configuration;


namespace Console_Config_User

{

    class UserInfo : System.Configuration.IConfigurationSectionHandler

    {


        public string _NAME;

        public string _ADDRESS;

        public string _HP;


        public UserInfo()

        {

            _NAME =

            _ADDRESS =

            _HP = "";

            

        }


        #region IConfigurationSectionHandler 멤버


        public object Create(object parent, object configContext, System.Xml.XmlNode section)

        {

            //throw new NotImplementedException();


            UserInfo obj = new UserInfo();


            ///

            /// section.SelectSingleNode("config").InnerText;

            ///

            obj._NAME    = section.SelectSingleNode("NAME").InnerText; // section 이용하여 config 값 넣는다.  

            obj._ADDRESS = section.SelectSingleNode("ADDRESS").InnerText; // section 이용하여 config 값 넣는다.

            obj._HP      = section.SelectSingleNode("HP").InnerText; // section 이용하여 config 값 넣는다.

            return obj;

        }


        #endregion

    }

}


- object parent, object configContext 이거 null 로 들어옴... 


Program.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;


using System.Configuration;


namespace Console_Config_User

{

    class Program

    {

        static void Main(string[] args)

        {


            //object config = ConfigurationManager.GetSection("unity");


            UserInfo container = new UserInfo();

            container = (UserInfo)ConfigurationManager.GetSection("unity");

            

        }

    }

}