■ 객체 메소드 동적 실행하기

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

using System;

using System.Reflection;

 

#region 실행하기 - Execute(assembly, fullTypeName, methodName, parameterArray)

 

/// <summary>

/// 실행하기

/// </summary>

/// <param name="assembly">어셈블리</param>

/// <param name="fullTypeName">완전한 타입명</param>

/// <param name="methodName">메소드명</param>

/// <param name="parameterArray">매개 변수 배열</param>

/// <returns>실행 결과</returns>

public object Execute(Assembly assembly, string fullTypeName, string methodName, params object[] parameterArray)

{

    Type classType = assembly.GetType(fullTypeName, true, false);

 

    object classObject = Activator.CreateInstance(classType);

 

    MethodInfo methodInfo = classType.GetMethod(methodName);

 

    object result = methodInfo.Invoke(classObject, parameterArray);

 

    return result;

}

 

#endregion

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

Posted by 사용자 icodebroker

댓글을 달아 주세요