728x90
728x170
▶ 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
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] 2진수(Binary Number) 문자열 구하기 (0) | 2020.02.15 |
---|---|
[C#/COMMON] Process 클래스 : StandardOutput 속성을 사용해 문자열 출력 결과 구하기 (0) | 2020.02.12 |
[C#/COMMON] Process 클래스 : StandardOutput 속성을 사용해 문자열 출력 결과 구하기 (0) | 2020.02.12 |
[C#/COMMON] Directory 클래스 : SetAccessControl 정적 메소드를 사용해 폴더 잠금(Folder Lock) 설정하기 (0) | 2020.02.12 |
[C#/COMMON] CodeDomProvider 클래스 : 런타임에서 C# 코드를 동적으로 컴파일하고 EXE 파일 생성하기 (0) | 2020.02.12 |
[C#/COMMON] Thread 클래스 : Interrupt 메소드를 사용해 스레드 종료하기 (0) | 2020.02.11 |
[C#/COMMON] IME 한글 입력 메시지 처리하기 (0) | 2020.02.11 |
[C#/COMMON] IList 인터페이스 : object 타입 배열로 변환하기 (0) | 2020.02.10 |
[C#/COMMON] 대용량 정렬 리스트 사용하기 (0) | 2020.02.07 |
[C#/COMMON] RegistryKey 클래스 : 신뢰할 수 있는 사이트 등록하기 (0) | 2020.02.03 |