DynamicMethod.Invoke 메서드

정의

지정된 문화권 정보와 함께 지정된 바인더의 제약 조건 하에서 지정된 매개 변수를 사용하여 동적 메서드를 호출합니다.

public:
 override System::Object ^ Invoke(System::Object ^ obj, System::Reflection::BindingFlags invokeAttr, System::Reflection::Binder ^ binder, cli::array <System::Object ^> ^ parameters, System::Globalization::CultureInfo ^ culture);
public override object? Invoke(object? obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder? binder, object?[]? parameters, System.Globalization.CultureInfo? culture);
public override object Invoke(object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object[] parameters, System.Globalization.CultureInfo culture);
override this.Invoke : obj * System.Reflection.BindingFlags * System.Reflection.Binder * obj[] * System.Globalization.CultureInfo -> obj
Public Overrides Function Invoke (obj As Object, invokeAttr As BindingFlags, binder As Binder, parameters As Object(), culture As CultureInfo) As Object

매개 변수

obj
Object

동적 메서드는 정적이므로 이 매개 변수는 무시됩니다. null을 지정합니다.

invokeAttr
BindingFlags

값의 BindingFlags 비트 조합입니다.

binder
Binder

Binder 바인딩, 인수 형식 강제 변환, 멤버 호출 및 리플렉션을 통해 개체 검색 MemberInfo 을 사용하도록 설정하는 개체입니다. 이 binder경우 null 기본 바인더가 사용됩니다. 자세한 내용은 Binder를 참조하세요.

parameters
Object[]

인수 목록입니다. 호출할 메서드의 매개 변수와 숫자, 순서 및 형식이 동일한 인수 배열입니다. 매개 변수가 없는 경우 이 매개 변수는 이어야 null합니다.

culture
CultureInfo

형식의 CultureInfo 강제 변환을 제어하는 데 사용되는 인스턴스입니다. 이 nullCultureInfo 경우 현재 스레드에 대한 스레드가 사용됩니다. 예를 들어 1000은 다른 문화권에 의해 다르게 표현되므로 1000 String 을 나타내는 값을 올바르게 변환 Double 하려면 이 정보가 필요합니다.

반품

Object 호출된 메서드의 반환 값을 포함하는 값입니다.

예외

호출 규칙은 VarArgs 지원되지 않습니다.

요소 parameters 수가 동적 메서드의 매개 변수 수와 일치하지 않습니다.

하나 이상의 요소 형식 parameters 이 동적 메서드의 해당 매개 변수 형식과 일치하지 않습니다.

동적 메서드는 모듈과 연결되고 익명으로 호스트되지 않으며 skipVisibilityfalse로 설정되었지만 동적 메서드는 public 또는 internal(Visual Basic Friend)이 아닌 멤버에 액세스합니다.

-또는-

동적 메서드는 익명으로 호스트되고 set를 사용하여 skipVisibility생성 false 되었지만 그렇지 않은 public멤버에 액세스합니다.

-또는-

동적 메서드에는 확인되지 않는 코드가 포함되어 있습니다. "비고에서 DynamicMethod에 대한 \"확인\" 섹션을 참조하세요."

예제

다음 코드 예제에서는 US-English 문화권을 사용하여 정확한 바인딩으로 동적 메서드를 호출합니다. 이 코드 예제는 클래스에 제공된 더 큰 예제의 DynamicMethod 일부입니다.

Console.WriteLine("\r\nUse the Invoke method to execute the dynamic method:");
// Create an array of arguments to use with the Invoke method.
object[] invokeArgs = {"\r\nHello, World!", 42};
// Invoke the dynamic method using the arguments. This is much
// slower than using the delegate, because you must create an
// array to contain the arguments, and value-type arguments
// must be boxed.
object objRet = hello.Invoke(null, BindingFlags.ExactBinding, null, invokeArgs, new CultureInfo("en-us"));
Console.WriteLine("hello.Invoke returned: " + objRet);
Console.WriteLine(vbCrLf & "Use the Invoke method to execute the dynamic method:")
' Create an array of arguments to use with the Invoke method.
Dim invokeArgs() As Object = {vbCrLf & "Hello, World!", 42}
' Invoke the dynamic method using the arguments. This is much
' slower than using the delegate, because you must create an
' array to contain the arguments, and value-type arguments
' must be boxed.
Dim objRet As Object = hello.Invoke(Nothing, _
    BindingFlags.ExactBinding, Nothing, invokeArgs, _
    New CultureInfo("en-us"))
Console.WriteLine("hello.Invoke returned: {0}", objRet)

설명

나열된 예외 외에도, 동적 메서드가 던진 모든 예외를 catch하도록 호출 코드를 준비해야 합니다.

메서드에서 만든 대리자를 사용하여 동적 메서드를 CreateDelegate 실행하는 것이 메서드를 Invoke 사용하여 실행하는 것보다 더 효율적입니다.

Invoke 메서드 또는 메서드를 호출하면 CreateDelegate 동적 메서드가 완료됩니다. 매개 변수 정의를 수정하거나 MSIL(Microsoft 중간 언어)을 더 내보내는 등 동적 메서드를 변경하려는 추가 시도는 무시됩니다. 예외가 throw되지 않습니다.

모든 동적 메서드는 정적이므로 obj 매개 변수는 항상 무시됩니다. 동적 메서드를 인스턴스 메서드인 것처럼 처리하려면 개체 인스턴스를 CreateDelegate(Type, Object) 사용하는 오버로드를 사용합니다.

동적 메서드에 매개 변수가 없으면 값 parameters 은 .이어야 null합니다. 그렇지 않으면 매개 변수 배열의 요소 수, 형식 및 순서가 동적 메서드의 매개 변수 수, 형식 및 순서와 동일해야 합니다.

메모

이 메서드 오버로드는 Invoke(Object, Object[]) 클래스에서 상속된 MethodBase 메서드 오버로드에 의해 호출되므로, 앞의 설명이 두 오버로드에 모두 적용됩니다.

이 메서드는 직접 권한을 요구하지 않지만 동적 메서드를 호출하면 메서드에 따라 보안 요구가 발생할 수 있습니다. 예를 들어, restrictedSkipVisibility 매개 변수가 false로 설정된 채로 생성된 익명으로 호스팅되는 동적 메서드에 대해서는 어떠한 요구도 없습니다. 반면, 대상 어셈블리의 숨겨진 멤버에 액세스할 수 있도록 설정된 restrictedSkipVisibility 메서드 true 를 만드는 경우 이 메서드는 대상 어셈블리 ReflectionPermission 의 사용 권한과 플래그를 ReflectionPermissionFlag.MemberAccess 함께 요구합니다.

적용 대상

추가 정보