첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

TestProject.zip
다운로드

▶ Program.cs

using System;

namespace TestProject
{
    /// <summary>
    /// 프로그램
    /// </summary>
    class Program
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region 프로그램 시작하기 - Main()

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        private static void Main()
        {
            TypeHelper.ExecuteMethod("TestProject.TestWriter", null, "Execute1", null);

            TypeHelper.ExecuteMethod("TestProject.TestWriter", null, "Execute2", new object[] { "VALUE" });

            TypeHelper.ExecuteMethod("TestProject.TestWriter", null, "Execute3", new object[] { "VALUE1", "VALUE2" });

            string result = (string)TypeHelper.ExecuteMethod("TestProject.TestWriter", new object[] { "VALUE" }, "GetValue", null);

            Console.WriteLine($"GET VALUE : {result}");
        }

        #endregion
    }
}

 

▶ TypeHelper.cs

using System;
using System.Reflection;

namespace TestProject
{
    /// <summary>
    /// 타입 헬퍼
    /// </summary>
    public static class TypeHelper
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 메소드 실행하기 - ExecuteMethod(typeName, constructorArgumentArray, methodName, methodArgumentArray)

        /// <summary>
        /// 메소드 실행하기
        /// </summary>
        /// <param name="typeName">타입명</param>
        /// <param name="constructorArgumentArray">생성자 인자 배열</param>
        /// <param name="methodName">메소드명</param>
        /// <param name="methodArgumentArray">메소드 인자 배열</param>
        /// <returns>메소드 실행 결과</returns>
        public static object ExecuteMethod
        (
            string   typeName,
            object[] constructorArgumentArray,
            string   methodName,
            object[] methodArgumentArray
        )
        {
            Type type = Type.GetType(typeName);

            object instance = Activator.CreateInstance(type, constructorArgumentArray);

            MethodInfo methodInfo = type.GetMethod(methodName);

            return methodInfo.Invoke(instance, methodArgumentArray);
        }

        #endregion
    }
}

 

▶ Writer.cs

using System;

namespace TestProject
{
    /// <summary>
    /// 테스트 작성기
    /// </summary>
    public class TestWriter
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field (Private)

        /// <summary>
        /// 값
        /// </summary>
        private string value;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - TestWriter()

        /// <summary>
        /// 생성자
        /// </summary>
        public TestWriter()
        {
        }

        #endregion
        #region 생성자 - TestWriter(value)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="value">값</param>
        public TestWriter(string value)
        {
            this.value = value;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 실행하기 1 - Execute1()

        /// <summary>
        /// 실행하기 1
        /// </summary>
        public void Execute1()
        {
            Console.WriteLine("실행 : ");
        }

        #endregion
        #region 실행하기 2 - Execute2(value1)

        /// <summary>
        /// 실행하기 2
        /// </summary>
        /// <param name="value1">값 1</param>
        public void Execute2(string value1)
        {
            Console.WriteLine($"실행 : {value1}");
        }

        #endregion
        #region 실행하기 3 - Execute3(value1, value2)

        /// <summary>
        /// 실행하기 3
        /// </summary>
        /// <param name="value1">값 1</param>
        /// <param name="value2">값 2</param>
        public void Execute3(string value1, string value2)
        {
            Console.WriteLine($"실행 : {value1}, {value2}");
        }

        #endregion

        #region 값 구하기 - GetValue()

        /// <summary>
        /// 값 구하기
        /// </summary>
        /// <returns>값</returns>
        public string GetValue()
        {
            return this.value;
        }

        #endregion
    }
}
728x90
그리드형(광고전용)
Posted by icodebroker
,