DynamicMethod 생성자

정의

동적 메서드를 만듭니다.

오버로드

DynamicMethod(String, Type, Type[])

메서드 이름, 반환 형식 및 매개 변수 형식을 지정하여 익명으로 호스트되는 동적 메서드를 초기화합니다.

DynamicMethod(String, Type, Type[], Boolean)

메서드 이름, 반환 형식, 매개 변수 형식, 그리고 동적 메서드의 MSIL(Microsoft Intermediate Language)에서 액세스하는 형식 및 멤버에 대해 JIT(적시) 가시성 검사를 건너뛰어야 하는지 여부를 지정하는 익명으로 호스팅된 동적 메서드를 초기화합니다.

DynamicMethod(String, Type, Type[], Module)

메서드 이름, 반환 형식, 매개 변수 형식 및 모듈을 지정하여 모듈 전체에서 사용되는 동적 메서드를 만듭니다.

DynamicMethod(String, Type, Type[], Type)

메서드 이름, 반환 형식, 매개 변수 형식 및 동적 메서드가 논리적으로 연결된 형식을 지정하여 동적 메서드를 만듭니다.

DynamicMethod(String, Type, Type[], Module, Boolean)

모듈 전체에 적용되는 동적 메서드를 만들어 메서드 이름, 반환 형식, 매개 변수 형식, 모듈을 지정하고, 동적 메서드의 MSIL(Microsoft Intermediate Language)이 액세스하는 형식과 멤버에 대해 JIT(just-in-time) 표시 유형 확인을 건너뛸지 여부를 지정합니다.

DynamicMethod(String, Type, Type[], Type, Boolean)

동적 메서드를 만들고, 메서드 이름, 반환 형식, 매개 변수 형식, 동적 메서드가 논리적으로 연결되는 형식, 동적 메서드의 MSIL(Microsoft Intermediate Language)이 액세스하는 형식과 멤버에 대해 JIT(just-in-time) 표시 유형 확인을 건너뛸지 여부를 지정합니다.

DynamicMethod(String, MethodAttributes, CallingConventions, Type, Type[], Module, Boolean)

모듈 전체에 적용되는 동적 메서드를 만들어 메서드 이름, 특성, 호출 규칙, 반환 형식, 매개 변수 형식, 모듈을 지정하고, 동적 메서드의 MSIL(Microsoft Intermediate Language)이 액세스하는 형식과 멤버에 대해 JIT(just-in-time) 표시 유형 확인을 건너뛸지 여부를 지정합니다.

DynamicMethod(String, MethodAttributes, CallingConventions, Type, Type[], Type, Boolean)

동적 메서드를 만들고, 메서드 이름, 특성, 호출 규칙, 반환 형식, 매개 변수 형식, 동적 메서드가 논리적으로 연결되는 형식, 동적 메서드의 MSIL(Microsoft Intermediate Language)이 액세스하는 형식과 멤버에 대해 JIT(just-in-time) 표시 유형 확인을 건너뛸지 여부를 지정합니다.

DynamicMethod(String, Type, Type[])

Source:
DynamicMethod.cs
Source:
DynamicMethod.cs
Source:
DynamicMethod.cs

메서드 이름, 반환 형식 및 매개 변수 형식을 지정하여 익명으로 호스트되는 동적 메서드를 초기화합니다.

public:
 DynamicMethod(System::String ^ name, Type ^ returnType, cli::array <Type ^> ^ parameterTypes);
public DynamicMethod (string name, Type? returnType, Type[]? parameterTypes);
public DynamicMethod (string name, Type returnType, Type[] parameterTypes);
new System.Reflection.Emit.DynamicMethod : string * Type * Type[] -> System.Reflection.Emit.DynamicMethod
Public Sub New (name As String, returnType As Type, parameterTypes As Type())

매개 변수

name
String

동적 메서드의 이름입니다. 이 항목에는 빈 문자열을 지정할 수 있지만 null은 지정할 수 없습니다.

returnType
Type

동적 메서드의 반환 형식을 지정하는 Type 개체이거나, 메서드에 반환 형식이 없으면 null입니다.

parameterTypes
Type[]

동적 메서드의 매개 변수 형식을 지정하는 Type 개체의 배열이거나, 메서드에 매개 변수가 없으면 null입니다.

예외

parameterTypes의 요소는 null 또는 Void입니다.

name이(가) null인 경우

2.1 이전의 .NET Framework 및 .NET Core 버전: returnType 은 를 반환true하는 IsByRef 형식입니다.

설명

이 생성자에서 만든 동적 메서드는 기존 형식 또는 모듈 대신 익명 어셈블리와 연결됩니다. 익명 어셈블리는 동적 메서드, 즉 다른 코드에서 격리하기 위한 샌드박스 환경을 제공하기 위해서만 존재합니다. 이 환경을 사용하면 동적 메서드를 부분적으로 신뢰할 수 있는 코드에서 내보내고 실행할 수 있습니다.

이 생성자는 동적 메서드의 MSIL(Microsoft Intermediate Language)에 대해 JIT(Just-In-Time) 표시 여부 검사가 적용되도록 지정합니다. 즉, 동적 메서드의 코드는 공용 클래스의 공용 메서드에 액세스할 수 있습니다. 메서드가 , protected또는 ( Visual Basic의 경우)Friend인 형식 또는 internal 멤버에 액세스하려고 하면 예외가 throw됩니다private. JIT 표시 유형 검사를 건너뛰는 기능이 제한된 동적 메서드를 만들려면 생성자를 사용합니다 DynamicMethod(String, Type, Type[], Boolean) .

익명으로 호스트되는 동적 메서드가 생성되면 내보내는 어셈블리의 호출 스택이 포함됩니다. 메서드가 호출될 때 내보내는 어셈블리의 사용 권한은 실제 호출자의 권한 대신 사용됩니다. 따라서 동적 메서드는 더 높은 신뢰 수준이 있는 어셈블리에 전달되고 실행되는 경우에도 이를 내보낸 어셈블리보다 높은 수준의 권한으로 실행할 수 없습니다.

이 생성자는 메서드 특성 MethodAttributes.Public 및 및 MethodAttributes.Static호출 규칙을 CallingConventions.Standard지정합니다.

참고

이 생성자는 .NET Framework 3.5 이상에서 도입되었습니다.

추가 정보

적용 대상

DynamicMethod(String, Type, Type[], Boolean)

Source:
DynamicMethod.cs
Source:
DynamicMethod.cs
Source:
DynamicMethod.cs

메서드 이름, 반환 형식, 매개 변수 형식, 그리고 동적 메서드의 MSIL(Microsoft Intermediate Language)에서 액세스하는 형식 및 멤버에 대해 JIT(적시) 가시성 검사를 건너뛰어야 하는지 여부를 지정하는 익명으로 호스팅된 동적 메서드를 초기화합니다.

public:
 DynamicMethod(System::String ^ name, Type ^ returnType, cli::array <Type ^> ^ parameterTypes, bool restrictedSkipVisibility);
public DynamicMethod (string name, Type? returnType, Type[]? parameterTypes, bool restrictedSkipVisibility);
public DynamicMethod (string name, Type returnType, Type[] parameterTypes, bool restrictedSkipVisibility);
new System.Reflection.Emit.DynamicMethod : string * Type * Type[] * bool -> System.Reflection.Emit.DynamicMethod
Public Sub New (name As String, returnType As Type, parameterTypes As Type(), restrictedSkipVisibility As Boolean)

매개 변수

name
String

동적 메서드의 이름입니다. 이 항목에는 빈 문자열을 지정할 수 있지만 null은 지정할 수 없습니다.

returnType
Type

동적 메서드의 반환 형식을 지정하는 Type 개체이거나, 메서드에 반환 형식이 없으면 null입니다.

parameterTypes
Type[]

동적 메서드의 매개 변수 형식을 지정하는 Type 개체의 배열이거나, 메서드에 매개 변수가 없으면 null입니다.

restrictedSkipVisibility
Boolean

동적 메서드의 MSIL에서 액세스하는 형식 및 멤버에 대해 JIT 가시성 검사를 건너뛰려면(단, 이러한 형식과 멤버를 포함하는 어셈블리의 트러스트 수준이 동적 메서드를 내보내는 호출 스택의 트러스트 수준보다 작거나 같아야 한다는 제한이 적용되는 경우) true이며, 건너뛰지 않으려면 false입니다.

예외

parameterTypes의 요소는 null 또는 Void입니다.

name이(가) null인 경우

2.1 이전의 .NET Framework 및 .NET Core 버전: returnType 은 를 반환true하는 IsByRef 형식입니다.

설명

이 생성자에서 만든 동적 메서드는 기존 형식 또는 모듈 대신 익명 어셈블리와 연결됩니다. 익명 어셈블리는 동적 메서드, 즉 다른 코드에서 격리하기 위한 샌드박스 환경을 제공하기 위해서만 존재합니다. 이 환경을 사용하면 동적 메서드를 부분적으로 신뢰할 수 있는 코드에서 내보내고 실행할 수 있습니다.

익명으로 호스트되는 동적 메서드는 , protected또는 (Friend Visual Basic의 경우)인 형식이나 internal 멤버private에 자동으로 액세스할 수 없습니다. 이는 연결된 scope 숨겨진 멤버에 액세스할 수 있는 기존 형식 또는 모듈과 연결된 동적 메서드와 다릅니다.

restrictedSkipVisibility 동적 메서드가 , 또는 인 internalprotected형식 또는 멤버에 액세스해야 하는지 private여부를 지정 true 합니다. 이렇게 하면 동적 메서드가 이러한 멤버에 대한 액세스를 제한합니다. 즉, 멤버는 다음 조건이 충족되는 경우에만 액세스할 수 있습니다.

  • 대상 멤버는 동적 메서드를 내보내는 호출 스택과 같거나 낮은 신뢰 수준이 있는 어셈블리에 속합니다.

  • 동적 메서드를 내보내는 호출 스택에는 플래그가 ReflectionPermissionFlag.RestrictedMemberAccess 부여됩니다ReflectionPermission. 이는 코드가 완전 신뢰로 실행될 때 항상 해당됩니다. 부분적으로 신뢰할 수 있는 코드의 경우 호스트가 명시적으로 권한을 부여하는 경우에만 true입니다.

    중요

    권한이 부여되지 않은 경우 이 생성자를 호출할 때가 CreateDelegate 아니라 가 호출되거나 동적 메서드가 호출될 때 보안 예외가 throw됩니다. 동적 메서드를 내보내는 데 특별한 권한이 필요하지 않습니다.

예를 들어 로 설정된 true 를 사용하여 만든 restrictedSkipVisibility 동적 메서드는 호출 스택에 제한된 멤버 액세스 권한이 부여된 경우 호출 스택에 있는 어셈블리의 프라이빗 멤버에 액세스할 수 있습니다. 동적 메서드가 호출 스택에서 부분적으로 신뢰할 수 있는 코드로 만들어지면 이러한 어셈블리가 완전히 신뢰할 수 있으므로 .NET Framework 어셈블리에서 형식의 프라이빗 멤버에 액세스할 수 없습니다.

가 이falserestrictedSkipVisibility JIT 표시 유형 검사가 적용됩니다. 동적 메서드의 코드는 공용 클래스의 공용 메서드에 액세스할 수 있으며 , protectedinternal또는 인 형식 또는 멤버에 액세스하려고 하면 예외가 throw됩니다private.

익명으로 호스트되는 동적 메서드가 생성되면 내보내는 어셈블리의 호출 스택이 포함됩니다. 메서드가 호출될 때 내보내기 호출 스택의 사용 권한은 실제 호출자의 권한 대신 사용됩니다. 따라서 동적 메서드는 더 높은 신뢰 수준이 있는 어셈블리에 전달되고 실행되는 경우에도 이를 내보낸 어셈블리보다 높은 수준의 권한으로 실행할 수 없습니다.

이 생성자는 메서드 특성 MethodAttributes.Public 및 및 MethodAttributes.Static호출 규칙을 CallingConventions.Standard지정합니다.

참고

이 생성자는 .NET Framework 3.5 이상에서 도입되었습니다.

추가 정보

적용 대상

DynamicMethod(String, Type, Type[], Module)

Source:
DynamicMethod.cs
Source:
DynamicMethod.cs
Source:
DynamicMethod.cs

메서드 이름, 반환 형식, 매개 변수 형식 및 모듈을 지정하여 모듈 전체에서 사용되는 동적 메서드를 만듭니다.

public:
 DynamicMethod(System::String ^ name, Type ^ returnType, cli::array <Type ^> ^ parameterTypes, System::Reflection::Module ^ m);
public DynamicMethod (string name, Type? returnType, Type[]? parameterTypes, System.Reflection.Module m);
public DynamicMethod (string name, Type returnType, Type[] parameterTypes, System.Reflection.Module m);
new System.Reflection.Emit.DynamicMethod : string * Type * Type[] * System.Reflection.Module -> System.Reflection.Emit.DynamicMethod
Public Sub New (name As String, returnType As Type, parameterTypes As Type(), m As Module)

매개 변수

name
String

동적 메서드의 이름입니다. 이 항목에는 빈 문자열을 지정할 수 있지만 null은 지정할 수 없습니다.

returnType
Type

동적 메서드의 반환 형식을 지정하는 Type 개체이거나, 메서드에 반환 형식이 없으면 null입니다.

parameterTypes
Type[]

동적 메서드의 매개 변수 형식을 지정하는 Type 개체의 배열이거나, 메서드에 매개 변수가 없으면 null입니다.

m
Module

동적 메서드를 논리적으로 연결할 모듈을 나타내는 Module 입니다.

예외

parameterTypes의 요소는 null 또는 Void입니다.

또는

m 이 동적 메서드에 대한 익명 호스팅을 제공하는 모듈입니다.

name이(가) null인 경우

또는

mnull입니다.

2.1 이전의 .NET Framework 및 .NET Core 버전: returnType 은 를 반환true하는 IsByRef 형식입니다.

예제

다음 코드 예제에서는 두 개의 매개 변수를 사용하는 동적 메서드를 만듭니다. 이 예제에서는 첫 번째 매개 변수를 콘솔에 인쇄하는 간단한 함수 본문을 내보내고 두 번째 매개 변수를 메서드의 반환 값으로 사용합니다. 이 예제에서는 대리자를 만들어 메서드를 완료하고, 다른 매개 변수를 사용하여 대리자를 호출하고, 마지막으로 메서드를 사용하여 동적 메서드를 Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) 호출합니다.

using namespace System;
using namespace System::Reflection;
using namespace System::Reflection::Emit;

public ref class Test
{   
};

// Declare a delegate that will be used to execute the completed
// dynamic method.
delegate int HelloInvoker(String^ msg, int ret);

int main()
{
    // Create an array that specifies the types of the parameters
    // of the dynamic method. This method has a string parameter
    // and an int parameter.
    array<Type^>^ helloArgs = {String::typeid, int::typeid};

    // Create a dynamic method with the name "Hello", a return type
    // of int, and two parameters whose types are specified by the
    // array helloArgs. Create the method in the module that
    // defines the Test class.
    DynamicMethod^ hello = gcnew DynamicMethod("Hello", 
        int::typeid,
        helloArgs,
        Test::typeid->Module);

    // Create an array that specifies the parameter types of the
    // overload of Console.WriteLine to be used in Hello.
    array<Type^>^ writeStringArgs = {String::typeid};
    // Get the overload of Console.WriteLine that has one
    // String parameter.
    MethodInfo^ writeString =
        Console::typeid->GetMethod("WriteLine", writeStringArgs);

    // Get an ILGenerator and emit a body for the dynamic method.
    ILGenerator^ ilgen = hello->GetILGenerator();
    // Load the first argument, which is a string, onto the stack.
    ilgen->Emit(OpCodes::Ldarg_0);
    // Call the overload of Console.WriteLine that prints a string.
    ilgen->EmitCall(OpCodes::Call, writeString, nullptr);
    // The Hello method returns the value of the second argument;
    // to do this, load the onto the stack and return.
    ilgen->Emit(OpCodes::Ldarg_1);
    ilgen->Emit(OpCodes::Ret);

    // Create a delegate that represents the dynamic method. This
    // action completes the method, and any further attempts to
    // change the method will cause an exception.
    HelloInvoker^ helloDelegate =
        (HelloInvoker^) hello->CreateDelegate(HelloInvoker::typeid);

    // Use the delegate to execute the dynamic method. Save and
    // print the return value.
    int returnValue = helloDelegate("\r\nHello, World!", 42);
    Console::WriteLine("helloDelegate(\"Hello, World!\", 42) returned {0}",
        returnValue);

    // Do it again, with different arguments.
    returnValue = helloDelegate("\r\nHi, Mom!", 5280);
    Console::WriteLine("helloDelegate(\"Hi, Mom!\", 5280) returned {0}",
        returnValue);

    // Create an array of arguments to use with the Invoke method.
    array<Object^>^ delegateArgs = {"\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 ValueType arguments
    // must be boxed.
    Object^ returnValueObject = hello->Invoke(nullptr, delegateArgs);
    Console::WriteLine("hello.Invoke returned {0}", returnValueObject);
}
using System;
using System.Reflection;
using System.Reflection.Emit;
using Microsoft.VisualBasic;

public class Test
{
    // Declare a delegate that will be used to execute the completed
    // dynamic method.
    private delegate int HelloInvoker(string msg, int ret);

    public static void Main()
    {
        // Create an array that specifies the types of the parameters
        // of the dynamic method. This method has a string parameter
        // and an int parameter.
        Type[] helloArgs = {typeof(string), typeof(int)};

        // Create a dynamic method with the name "Hello", a return type
        // of int, and two parameters whose types are specified by the
        // array helloArgs. Create the method in the module that
        // defines the Test class.
        DynamicMethod hello = new DynamicMethod("Hello",
            typeof(int),
            helloArgs,
            typeof(Test).Module);

        // Create an array that specifies the parameter types of the
        // overload of Console.WriteLine to be used in Hello.
        Type[] writeStringArgs = {typeof(string)};
        // Get the overload of Console.WriteLine that has one
        // String parameter.
        MethodInfo writeString =
            typeof(Console).GetMethod("WriteLine", writeStringArgs);

        // Get an ILGenerator and emit a body for the dynamic method.
        ILGenerator il = hello.GetILGenerator();
        // Load the first argument, which is a string, onto the stack.
        il.Emit(OpCodes.Ldarg_0);
        // Call the overload of Console.WriteLine that prints a string.
        il.EmitCall(OpCodes.Call, writeString, null);
        // The Hello method returns the value of the second argument;
        // to do this, load the onto the stack and return.
        il.Emit(OpCodes.Ldarg_1);
        il.Emit(OpCodes.Ret);

        // Create a delegate that represents the dynamic method. This
        // action completes the method, and any further attempts to
        // change the method will cause an exception.
        HelloInvoker hi =
            (HelloInvoker) hello.CreateDelegate(typeof(HelloInvoker));

        // Use the delegate to execute the dynamic method. Save and
        // print the return value.
        int retval = hi("\r\nHello, World!", 42);
        Console.WriteLine("Executing delegate hi(\"Hello, World!\", 42) returned {0}",
            retval);

        // Do it again, with different arguments.
        retval = hi("\r\nHi, Mom!", 5280);
        Console.WriteLine("Executing delegate hi(\"Hi, Mom!\", 5280) returned {0}",
            retval);

        // 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 ValueType arguments
        // must be boxed.
        object objRet = hello.Invoke(null, invokeArgs);
        Console.WriteLine("hello.Invoke returned {0}", objRet);
    }
}
Imports System.Reflection
Imports System.Reflection.Emit

Public Class Test
    ' Declare a delegate that will be used to execute the completed
    ' dynamic method. 
    Private Delegate Function HelloInvoker(ByVal msg As String, _
        ByVal ret As Integer) As Integer

    Public Shared Sub Main()
        ' Create an array that specifies the types of the parameters
        ' of the dynamic method. This method has a String parameter
        ' and an Integer parameter.
        Dim helloArgs() As Type = {GetType(String), GetType(Integer)}

        ' Create a dynamic method with the name "Hello", a return type
        ' of Integer, and two parameters whose types are specified by
        ' the array helloArgs. Create the method in the module that
        ' defines the Test class.
        Dim hello As New DynamicMethod("Hello", _
            GetType(Integer), _
            helloArgs, _
            GetType(Test).Module)

        ' Create an array that specifies the parameter types of the
        ' overload of Console.WriteLine to be used in Hello.
        Dim writeStringArgs() As Type = {GetType(String)}
        ' Get the overload of Console.WriteLine that has one
        ' String parameter.
        Dim writeString As MethodInfo = GetType(Console). _
            GetMethod("WriteLine", writeStringArgs) 

        ' Get an ILGenerator and emit a body for the dynamic method.
        Dim il As ILGenerator = hello.GetILGenerator()
        ' Load the first argument, which is a string, onto the stack.
        il.Emit(OpCodes.Ldarg_0)
        ' Call the overload of Console.WriteLine that prints a string.
        il.EmitCall(OpCodes.Call, writeString, Nothing)
        ' The Hello method returns the value of the second argument;
        ' to do this, load the onto the stack and return.
        il.Emit(OpCodes.Ldarg_1)
        il.Emit(OpCodes.Ret)

        ' Create a delegate that represents the dynamic method. This
        ' action completes the method, and any further attempts to
        ' change the method will cause an exception.
    Dim hi As HelloInvoker = _
            hello.CreateDelegate(GetType(HelloInvoker))

        ' Use the delegate to execute the dynamic method. Save and
        ' print the return value.
        Dim retval As Integer = hi(vbCrLf & "Hello, World!", 42)
        Console.WriteLine("Executing delegate hi(""Hello, World!"", 42) returned " _
            & retval)

        ' Do it again, with different arguments.
        retval = hi(vbCrLf & "Hi, Mom!", 5280)
        Console.WriteLine("Executing delegate hi(""Hi, Mom!"", 5280) returned " _
            & retval)

        ' 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 ValueType arguments
        ' must be boxed. Note that this overload of Invoke is 
        ' inherited from MethodBase, and simply calls the more 
        ' complete overload of Invoke.
        Dim objRet As Object = hello.Invoke(Nothing, invokeArgs)
        Console.WriteLine("hello.Invoke returned " & objRet)
    End Sub
End Class

' This code example produces the following output:
'
'Hello, World!
'Executing delegate hi("Hello, World!", 42) returned 42
'
'Hi, Mom!
'Executing delegate hi("Hi, Mom!", 5280) returned 5280
'
'Hello, World!
'hello.Invoke returned 42
'

설명

이 생성자는 메서드 특성 MethodAttributes.Public 및 를 지정하고 MethodAttributes.Static규칙을 CallingConventions.Standard호출하며 JIT(Just-In-Time) 표시 여부 검사를 건너뛰지 않습니다.

이 생성자로 만든 동적 메서드는 모듈 m에 포함된 모든 형식의 public 및 internal (FriendVisual Basic의 경우) 멤버에 액세스할 수 있습니다.

참고

이전 버전과의 호환성을 위해 이 생성자는 다음 조건이 모두 true m 인 경우 플래그를 요구합니다 SecurityPermissionSecurityPermissionFlag.ControlEvidence. 는 호출 모듈 이외의 모듈이고 플래그를 사용하는 에 대한 ReflectionPermissionReflectionPermissionFlag.MemberAccess 수요가 실패했습니다. 에 대한 SecurityPermission 수요가 성공하면 작업이 허용됩니다.

추가 정보

적용 대상

DynamicMethod(String, Type, Type[], Type)

Source:
DynamicMethod.cs
Source:
DynamicMethod.cs
Source:
DynamicMethod.cs

메서드 이름, 반환 형식, 매개 변수 형식 및 동적 메서드가 논리적으로 연결된 형식을 지정하여 동적 메서드를 만듭니다.

public:
 DynamicMethod(System::String ^ name, Type ^ returnType, cli::array <Type ^> ^ parameterTypes, Type ^ owner);
public DynamicMethod (string name, Type? returnType, Type[]? parameterTypes, Type owner);
public DynamicMethod (string name, Type returnType, Type[] parameterTypes, Type owner);
new System.Reflection.Emit.DynamicMethod : string * Type * Type[] * Type -> System.Reflection.Emit.DynamicMethod
Public Sub New (name As String, returnType As Type, parameterTypes As Type(), owner As Type)

매개 변수

name
String

동적 메서드의 이름입니다. 이 항목에는 빈 문자열을 지정할 수 있지만 null은 지정할 수 없습니다.

returnType
Type

동적 메서드의 반환 형식을 지정하는 Type 개체이거나, 메서드에 반환 형식이 없으면 null입니다.

parameterTypes
Type[]

동적 메서드의 매개 변수 형식을 지정하는 Type 개체의 배열이거나, 메서드에 매개 변수가 없으면 null입니다.

owner
Type

동적 메서드가 논리적으로 연결되는 Type 입니다. 동적 메서드에 해당 형식의 모든 멤버에 대한 액세스 권한이 있습니다.

예외

parameterTypes의 요소는 null 또는 Void입니다.

또는

owner 가 인터페이스, 배열, 개방형 제네릭 형식, 제네릭 형식 또는 메서드의 형식 매개 변수입니다.

name이(가) null인 경우

또는

ownernull입니다.

2.1보다 오래된 .NET Framework 및 .NET Core 버전: returnType 은 를 반환true하는 IsByRef 형식입니다.

예제

다음 코드 예제에서는 논리적으로 연결 된 형식을 만듭니다 DynamicMethod . 이 연결은 해당 형식의 프라이빗 멤버에 대한 액세스 권한을 부여합니다.

이 코드 예제에서는 프라이빗 필드가 있는 라는 Example 클래스, 첫 번째 클래스에서 파생되는 라는 DerivedFromExample 클래스, 형식 및 의 매개 변수를 반환 Int32 하고 포함하는 라는 UseLikeStatic 대리자 형식Example, Int32형식의 Int32매개 변수를 반환하고 포함하는 대리 UseLikeInstanceInt32 자 형식을 정의합니다.

그런 다음, 예제 코드는 의 instance Example 프라이빗 필드를 변경하고 이전 값을 반환하는 을 만듭니다DynamicMethod.

참고

일반적으로 클래스의 내부 필드를 변경하는 것은 개체 지향 코딩 연습에 적합하지 않습니다.

예제 코드는 의 instance Example 만든 다음 두 개의 대리자를 만듭니다. 첫 번째는 동적 메서드와 동일한 매개 변수를 포함하는 형식 UseLikeStatic입니다. 두 번째는 형식 UseLikeInstance이며 첫 번째 매개 변수(형식 Example)가 없습니다. 이 대리자는 메서드 오버로드를 CreateDelegate(Type, Object) 사용하여 만들어집니다. 해당 메서드 오버로드의 두 번째 매개 변수는 의 Exampleinstance, 이 경우 방금 만든 instance 새로 만든 대리자에게 바인딩됩니다. 해당 대리자를 호출할 때마다 동적 메서드는 의 Example바인딩된 instance 작동합니다.

참고

이는 메서드의 새 오버로드와 함께 .NET Framework 2.0에 도입된 대리자 바인딩에 대한 완화된 규칙의 Delegate.CreateDelegate 예입니다. 자세한 내용은 Delegate 클래스를 참조하세요.

UseLikeStatic 대리자를 호출하여 대리자의 instance ExampleUseLikeInstance 전달합니다. 그런 다음 대리자를 UseLikeInstance 호출하여 두 대리자 모두 의 동일한 instance Example작동합니다. 내부 필드 값의 변경 내용은 각 호출 후에 표시됩니다. 마지막으로 대리자는 UseLikeInstance 의 instance DerivedFromExample바인딩되고 대리자 호출이 반복됩니다.

using System;
using System.Reflection;
using System.Reflection.Emit;

// These classes are for demonstration purposes.
//
public class Example
{
    private int id = 0;
    public Example(int id)
    {
        this.id = id;
    }
    public int ID { get { return id; }}
}

public class DerivedFromExample : Example
{
    public DerivedFromExample(int id) : base(id) {}
}

// Two delegates are declared: UseLikeInstance treats the dynamic
// method as if it were an instance method, and UseLikeStatic
// treats the dynamic method in the ordinary fashion.
//
public delegate int UseLikeInstance(int newID);
public delegate int UseLikeStatic(Example ex, int newID);

public class Demo
{
    public static void Main()
    {
        // This dynamic method changes the private id field. It has
        // no name; it returns the old id value (return type int);
        // it takes two parameters, an instance of Example and
        // an int that is the new value of id; and it is declared
        // with Example as the owner type, so it can access all
        // members, public and private.
        //
        DynamicMethod changeID = new DynamicMethod(
            "",
            typeof(int),
            new Type[] { typeof(Example), typeof(int) },
            typeof(Example)
        );

        // Get a FieldInfo for the private field 'id'.
        FieldInfo fid = typeof(Example).GetField(
            "id",
            BindingFlags.NonPublic | BindingFlags.Instance
        );

        ILGenerator ilg = changeID.GetILGenerator();

        // Push the current value of the id field onto the
        // evaluation stack. It's an instance field, so load the
        // instance of Example before accessing the field.
        ilg.Emit(OpCodes.Ldarg_0);
        ilg.Emit(OpCodes.Ldfld, fid);

        // Load the instance of Example again, load the new value
        // of id, and store the new field value.
        ilg.Emit(OpCodes.Ldarg_0);
        ilg.Emit(OpCodes.Ldarg_1);
        ilg.Emit(OpCodes.Stfld, fid);

        // The original value of the id field is now the only
        // thing on the stack, so return from the call.
        ilg.Emit(OpCodes.Ret);

        // Create a delegate that uses changeID in the ordinary
        // way, as a static method that takes an instance of
        // Example and an int.
        //
        UseLikeStatic uls =
            (UseLikeStatic) changeID.CreateDelegate(
                typeof(UseLikeStatic)
            );

        // Create an instance of Example with an id of 42.
        //
        Example ex = new Example(42);

        // Create a delegate that is bound to the instance of
        // of Example. This is possible because the first
        // parameter of changeID is of type Example. The
        // delegate has all the parameters of changeID except
        // the first.
        UseLikeInstance uli =
            (UseLikeInstance) changeID.CreateDelegate(
                typeof(UseLikeInstance),
                ex
            );

        // First, change the value of id by calling changeID as
        // a static method, passing in the instance of Example.
        //
        Console.WriteLine(
            "Change the value of id; previous value: {0}",
            uls(ex, 1492)
        );

        // Change the value of id again using the delegate bound
        // to the instance of Example.
        //
        Console.WriteLine(
            "Change the value of id; previous value: {0}",
            uli(2700)
        );

        Console.WriteLine("Final value of id: {0}", ex.ID);

        // Now repeat the process with a class that derives
        // from Example.
        //
        DerivedFromExample dfex = new DerivedFromExample(71);

        uli = (UseLikeInstance) changeID.CreateDelegate(
                typeof(UseLikeInstance),
                dfex
            );

        Console.WriteLine(
            "Change the value of id; previous value: {0}",
            uls(dfex, 73)
        );
        Console.WriteLine(
            "Change the value of id; previous value: {0}",
            uli(79)
        );
        Console.WriteLine("Final value of id: {0}", dfex.ID);
    }
}

/* This code example produces the following output:

Change the value of id; previous value: 42
Change the value of id; previous value: 1492
Final value of id: 2700
Change the value of id; previous value: 71
Change the value of id; previous value: 73
Final value of id: 79
 */
Imports System.Reflection
Imports System.Reflection.Emit

' These classes are for demonstration purposes.
'
Public Class Example
    Private _id As Integer = 0
    
    Public Sub New(ByVal newId As Integer) 
        _id = newId    
    End Sub
    
    Public ReadOnly Property ID() As Integer 
        Get
            Return _id
        End Get
    End Property 
End Class

Public Class DerivedFromExample
    Inherits Example
    
    Public Sub New(ByVal newId As Integer) 
        MyBase.New(newId)
    End Sub
End Class
 
' Two delegates are declared: UseLikeInstance treats the dynamic
' method as if it were an instance method, and UseLikeStatic
' treats the dynamic method in the ordinary fashion.
' 
Public Delegate Function UseLikeInstance(ByVal newID As Integer) _
    As Integer 
Public Delegate Function UseLikeStatic(ByVal ex As Example, _
    ByVal newID As Integer) As Integer 

Public Class Demo
    
    Public Shared Sub Main() 
        ' This dynamic method changes the private _id field. It 
        ' has no name; it returns the old _id value (return type 
        ' Integer); it takes two parameters, an instance of Example 
        ' and an Integer that is the new value of _id; and it is 
        ' declared with Example as the owner type, so it can 
        ' access all members, public and private.
        '
        Dim changeID As New DynamicMethod( _
            "", _
            GetType(Integer), _
            New Type() {GetType(Example), GetType(Integer)}, _
            GetType(Example) _
        )
        
        ' Get a FieldInfo for the private field '_id'.
        Dim fid As FieldInfo = GetType(Example).GetField( _
            "_id", _
            BindingFlags.NonPublic Or BindingFlags.Instance _
        )
        
        Dim ilg As ILGenerator = changeID.GetILGenerator()
        
        ' Push the current value of the id field onto the 
        ' evaluation stack. It's an instance field, so load the
        ' instance of Example before accessing the field.
        ilg.Emit(OpCodes.Ldarg_0)
        ilg.Emit(OpCodes.Ldfld, fid)
        
        ' Load the instance of Example again, load the new value 
        ' of id, and store the new field value. 
        ilg.Emit(OpCodes.Ldarg_0)
        ilg.Emit(OpCodes.Ldarg_1)
        ilg.Emit(OpCodes.Stfld, fid)
        
        ' The original value of the id field is now the only 
        ' thing on the stack, so return from the call.
        ilg.Emit(OpCodes.Ret)
        
        
        ' Create a delegate that uses changeID in the ordinary
        ' way, as a static method that takes an instance of
        ' Example and an Integer.
        '
        Dim uls As UseLikeStatic = CType( _
            changeID.CreateDelegate(GetType(UseLikeStatic)), _
            UseLikeStatic _
        )
        
        ' Create an instance of Example with an id of 42.
        '
        Dim ex As New Example(42)
        
        ' Create a delegate that is bound to the instance of 
        ' of Example. This is possible because the first 
        ' parameter of changeID is of type Example. The 
        ' delegate has all the parameters of changeID except
        ' the first.
        Dim uli As UseLikeInstance = CType( _
            changeID.CreateDelegate( _
                GetType(UseLikeInstance), _
                ex), _
            UseLikeInstance _
        )
        
        ' First, change the value of _id by calling changeID as
        ' a static method, passing in the instance of Example.
        '
        Console.WriteLine( _
            "Change the value of _id; previous value: {0}", _
            uls(ex, 1492) _
        )
        
        ' Change the value of _id again using the delegate 
        ' bound to the instance of Example.
        '
        Console.WriteLine( _
            "Change the value of _id; previous value: {0}", _
            uli(2700) _
        )
        
        Console.WriteLine("Final value of _id: {0}", ex.ID)
    

        ' Now repeat the process with a class that derives
        ' from Example.
        '
        Dim dfex As New DerivedFromExample(71)

        uli = CType( _
            changeID.CreateDelegate( _
                GetType(UseLikeInstance), _
                dfex), _
            UseLikeInstance _
        )

        Console.WriteLine( _
            "Change the value of _id; previous value: {0}", _
            uls(dfex, 73) _
        )
        Console.WriteLine( _
            "Change the value of _id; previous value: {0}", _
            uli(79) _
        )
        Console.WriteLine("Final value of _id: {0}", dfex.ID)

    End Sub
End Class

' This code example produces the following output:
'
'Change the value of _id; previous value: 42
'Change the value of _id; previous value: 1492
'Final value of _id: 2700
'Change the value of _id; previous value: 71
'Change the value of _id; previous value: 73
'Final value of _id: 79'

설명

이 생성자를 사용하여 만든 동적 메서드는 형식 owner의 모든 멤버에 액세스할 수 있으며 를 포함하는 모듈의 다른 모든 형식의 public 및 internal (Friend Visual Basic의 경우) 멤버에 액세스할 수 있습니다 owner.

이 생성자는 메서드 특성 MethodAttributes.Public 및 를 지정하고 MethodAttributes.Static규칙을 CallingConventions.Standard호출하며 JIT(Just-In-Time) 표시 유형 검사를 건너뛰지 않습니다.

참고

이전 버전과의 호환성을 위해 이 생성자는 다음 조건이 모두 true owner 인 경우 플래그를 SecurityPermissionFlag.ControlEvidence 요구 SecurityPermission 합니다. 가 호출 모듈 이외의 모듈에 있고 플래그에 대한 ReflectionPermissionReflectionPermissionFlag.MemberAccess 요구가 실패했습니다. 에 대한 SecurityPermission 수요가 성공하면 작업이 허용됩니다.

추가 정보

적용 대상

DynamicMethod(String, Type, Type[], Module, Boolean)

Source:
DynamicMethod.cs
Source:
DynamicMethod.cs
Source:
DynamicMethod.cs

모듈 전체에 적용되는 동적 메서드를 만들어 메서드 이름, 반환 형식, 매개 변수 형식, 모듈을 지정하고, 동적 메서드의 MSIL(Microsoft Intermediate Language)이 액세스하는 형식과 멤버에 대해 JIT(just-in-time) 표시 유형 확인을 건너뛸지 여부를 지정합니다.

public:
 DynamicMethod(System::String ^ name, Type ^ returnType, cli::array <Type ^> ^ parameterTypes, System::Reflection::Module ^ m, bool skipVisibility);
public DynamicMethod (string name, Type? returnType, Type[]? parameterTypes, System.Reflection.Module m, bool skipVisibility);
public DynamicMethod (string name, Type returnType, Type[] parameterTypes, System.Reflection.Module m, bool skipVisibility);
new System.Reflection.Emit.DynamicMethod : string * Type * Type[] * System.Reflection.Module * bool -> System.Reflection.Emit.DynamicMethod
Public Sub New (name As String, returnType As Type, parameterTypes As Type(), m As Module, skipVisibility As Boolean)

매개 변수

name
String

동적 메서드의 이름입니다. 이 항목에는 빈 문자열을 지정할 수 있지만 null은 지정할 수 없습니다.

returnType
Type

동적 메서드의 반환 형식을 지정하는 Type 개체이거나, 메서드에 반환 형식이 없으면 null입니다.

parameterTypes
Type[]

동적 메서드의 매개 변수 형식을 지정하는 Type 개체의 배열이거나, 메서드에 매개 변수가 없으면 null입니다.

m
Module

동적 메서드를 논리적으로 연결할 모듈을 나타내는 Module 입니다.

skipVisibility
Boolean

동적 메서드의 MSIL에서 액세스하는 형식 및 멤버에서 JIT 표시 유형 확인을 건너뛰는 경우true 입니다.

예외

parameterTypes의 요소는 null 또는 Void입니다.

또는

m 이 동적 메서드에 대한 익명 호스팅을 제공하는 모듈입니다.

name이(가) null인 경우

또는

mnull입니다.

2.1보다 오래된 .NET Framework 및 .NET Core 버전: returnType 은 를 반환true하는 IsByRef 형식입니다.

설명

이 생성자는 메서드 특성 MethodAttributes.Public 및 및 MethodAttributes.Static호출 규칙을 CallingConventions.Standard지정합니다.

이 생성자를 사용하여 만든 동적 메서드는 포함된 모듈 m에 있는 모든 형식의 public 및 internal (FriendVisual Basic의 경우) 멤버에 액세스할 수 있습니다. JIT 컴파일러의 표시 유형 검사를 건너뛰면 동적 메서드가 다른 모든 형식의 프라이빗 및 보호된 멤버에도 액세스할 수 있습니다. 예를 들어 개체를 직렬화하는 코드를 작성할 때 유용합니다.

참고

이전 버전과의 호환성을 위해 이 생성자는 다음 조건이 모두 true m 인 경우 플래그를 SecurityPermissionFlag.ControlEvidence 요구 SecurityPermission 합니다. 은 호출 모듈 이외의 모듈이고 플래그를 사용하는 에 대한 ReflectionPermissionReflectionPermissionFlag.MemberAccess 요구가 실패했습니다. 에 대한 SecurityPermission 수요가 성공하면 작업이 허용됩니다.

추가 정보

적용 대상

DynamicMethod(String, Type, Type[], Type, Boolean)

Source:
DynamicMethod.cs
Source:
DynamicMethod.cs
Source:
DynamicMethod.cs

동적 메서드를 만들고, 메서드 이름, 반환 형식, 매개 변수 형식, 동적 메서드가 논리적으로 연결되는 형식, 동적 메서드의 MSIL(Microsoft Intermediate Language)이 액세스하는 형식과 멤버에 대해 JIT(just-in-time) 표시 유형 확인을 건너뛸지 여부를 지정합니다.

public:
 DynamicMethod(System::String ^ name, Type ^ returnType, cli::array <Type ^> ^ parameterTypes, Type ^ owner, bool skipVisibility);
public DynamicMethod (string name, Type? returnType, Type[]? parameterTypes, Type owner, bool skipVisibility);
public DynamicMethod (string name, Type returnType, Type[] parameterTypes, Type owner, bool skipVisibility);
new System.Reflection.Emit.DynamicMethod : string * Type * Type[] * Type * bool -> System.Reflection.Emit.DynamicMethod
Public Sub New (name As String, returnType As Type, parameterTypes As Type(), owner As Type, skipVisibility As Boolean)

매개 변수

name
String

동적 메서드의 이름입니다. 이 항목에는 빈 문자열을 지정할 수 있지만 null은 지정할 수 없습니다.

returnType
Type

동적 메서드의 반환 형식을 지정하는 Type 개체이거나, 메서드에 반환 형식이 없으면 null입니다.

parameterTypes
Type[]

동적 메서드의 매개 변수 형식을 지정하는 Type 개체의 배열이거나, 메서드에 매개 변수가 없으면 null입니다.

owner
Type

동적 메서드가 논리적으로 연결되는 Type 입니다. 동적 메서드에 해당 형식의 모든 멤버에 대한 액세스 권한이 있습니다.

skipVisibility
Boolean

동적 메서드의 MSIL에서 액세스하는 형식 및 멤버에서 JIT 표시 유형 확인을 건너뛰는 경우true 이고, 그러지 않으면 false입니다.

예외

parameterTypes의 요소는 null 또는 Void입니다.

또는

owner 가 인터페이스, 배열, 개방형 제네릭 형식, 제네릭 형식 또는 메서드의 형식 매개 변수입니다.

name이(가) null인 경우

또는

ownernull입니다.

2.1보다 오래된 .NET Framework 및 .NET Core 버전: returnType 은 를 반환true하는 IsByRef 형식입니다.

설명

이 생성자를 사용하여 만든 동적 메서드는 형식 owner의 모든 멤버에 액세스할 수 있으며 를 포함하는 모듈의 다른 모든 형식의 public 및 internal (Friend Visual Basic의 경우) 멤버에 액세스할 수 있습니다 owner. JIT 컴파일러의 표시 유형 검사를 건너뛰면 동적 메서드가 다른 모든 형식의 프라이빗 및 보호된 멤버에도 액세스할 수 있습니다. 예를 들어 개체를 직렬화하는 코드를 작성할 때 유용합니다.

이 생성자는 메서드 특성 MethodAttributes.Public 및 및 MethodAttributes.Static호출 규칙을 CallingConventions.Standard지정합니다.

참고

이전 버전과의 호환성을 위해 이 생성자는 다음 조건이 모두 true owner 인 경우 플래그를 SecurityPermissionFlag.ControlEvidence 요구 SecurityPermission 합니다. 가 호출 모듈 이외의 모듈에 있고 플래그에 대한 ReflectionPermissionReflectionPermissionFlag.MemberAccess 요구가 실패했습니다. 에 대한 SecurityPermission 수요가 성공하면 작업이 허용됩니다.

추가 정보

적용 대상

DynamicMethod(String, MethodAttributes, CallingConventions, Type, Type[], Module, Boolean)

Source:
DynamicMethod.cs
Source:
DynamicMethod.cs
Source:
DynamicMethod.cs

모듈 전체에 적용되는 동적 메서드를 만들어 메서드 이름, 특성, 호출 규칙, 반환 형식, 매개 변수 형식, 모듈을 지정하고, 동적 메서드의 MSIL(Microsoft Intermediate Language)이 액세스하는 형식과 멤버에 대해 JIT(just-in-time) 표시 유형 확인을 건너뛸지 여부를 지정합니다.

public:
 DynamicMethod(System::String ^ name, System::Reflection::MethodAttributes attributes, System::Reflection::CallingConventions callingConvention, Type ^ returnType, cli::array <Type ^> ^ parameterTypes, System::Reflection::Module ^ m, bool skipVisibility);
public DynamicMethod (string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes, System.Reflection.Module m, bool skipVisibility);
public DynamicMethod (string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] parameterTypes, System.Reflection.Module m, bool skipVisibility);
new System.Reflection.Emit.DynamicMethod : string * System.Reflection.MethodAttributes * System.Reflection.CallingConventions * Type * Type[] * System.Reflection.Module * bool -> System.Reflection.Emit.DynamicMethod
Public Sub New (name As String, attributes As MethodAttributes, callingConvention As CallingConventions, returnType As Type, parameterTypes As Type(), m As Module, skipVisibility As Boolean)

매개 변수

name
String

동적 메서드의 이름입니다. 이 항목에는 빈 문자열을 지정할 수 있지만 null은 지정할 수 없습니다.

attributes
MethodAttributes

동적 메서드의 특성을 지정하는 MethodAttributes 값의 비트 조합입니다. 허용되는 유일한 조합은 PublicStatic입니다.

callingConvention
CallingConventions

동적 메서드의 호출 규칙입니다. Standard이어야 합니다.

returnType
Type

동적 메서드의 반환 형식을 지정하는 Type 개체이거나, 메서드에 반환 형식이 없으면 null입니다.

parameterTypes
Type[]

동적 메서드의 매개 변수 형식을 지정하는 Type 개체의 배열이거나, 메서드에 매개 변수가 없으면 null입니다.

m
Module

동적 메서드를 논리적으로 연결할 모듈을 나타내는 Module 입니다.

skipVisibility
Boolean

동적 메서드의 MSIL에서 액세스하는 형식 및 멤버에서 JIT 표시 유형 확인을 건너뛰는 경우true 이고, 그러지 않으면 false입니다.

예외

parameterTypes의 요소는 null 또는 Void입니다.

또는

m 이 동적 메서드에 대한 익명 호스팅을 제공하는 모듈입니다.

name이(가) null인 경우

또는

m이(가) null인 경우

attributesPublicStatic이외의 플래그 조합입니다.

또는

callingConventionStandard가 아닙니다.

또는

returnTypeIsByReftrue를 반환하는 형식입니다.

설명

이 생성자를 사용하여 만든 동적 메서드는 모듈 m에 포함된 모든 공용 및 내부 형식의 public 및 internal (FriendVisual Basic의 경우) 멤버에 액세스할 수 있습니다.

JIT 컴파일러의 표시 유형 검사를 건너뛰면 동적 메서드가 모듈 및 다른 모든 어셈블리의 다른 모든 형식의 프라이빗 및 보호된 멤버에 액세스할 수 있습니다. 예를 들어 개체를 직렬화하는 코드를 작성할 때 유용합니다.

참고

이전 버전과의 호환성을 위해 이 생성자는 다음 조건이 모두 true m 인 경우 플래그를 SecurityPermissionFlag.ControlEvidence 요구 SecurityPermission 합니다. 은 호출 모듈 이외의 모듈이고 플래그를 사용하는 에 대한 ReflectionPermissionReflectionPermissionFlag.MemberAccess 요구가 실패했습니다. 에 대한 SecurityPermission 수요가 성공하면 작업이 허용됩니다.

추가 정보

적용 대상

DynamicMethod(String, MethodAttributes, CallingConventions, Type, Type[], Type, Boolean)

Source:
DynamicMethod.cs
Source:
DynamicMethod.cs
Source:
DynamicMethod.cs

동적 메서드를 만들고, 메서드 이름, 특성, 호출 규칙, 반환 형식, 매개 변수 형식, 동적 메서드가 논리적으로 연결되는 형식, 동적 메서드의 MSIL(Microsoft Intermediate Language)이 액세스하는 형식과 멤버에 대해 JIT(just-in-time) 표시 유형 확인을 건너뛸지 여부를 지정합니다.

public:
 DynamicMethod(System::String ^ name, System::Reflection::MethodAttributes attributes, System::Reflection::CallingConventions callingConvention, Type ^ returnType, cli::array <Type ^> ^ parameterTypes, Type ^ owner, bool skipVisibility);
public DynamicMethod (string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes, Type owner, bool skipVisibility);
public DynamicMethod (string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Type owner, bool skipVisibility);
new System.Reflection.Emit.DynamicMethod : string * System.Reflection.MethodAttributes * System.Reflection.CallingConventions * Type * Type[] * Type * bool -> System.Reflection.Emit.DynamicMethod
Public Sub New (name As String, attributes As MethodAttributes, callingConvention As CallingConventions, returnType As Type, parameterTypes As Type(), owner As Type, skipVisibility As Boolean)

매개 변수

name
String

동적 메서드의 이름입니다. 이 항목에는 빈 문자열을 지정할 수 있지만 null은 지정할 수 없습니다.

attributes
MethodAttributes

동적 메서드의 특성을 지정하는 MethodAttributes 값의 비트 조합입니다. 허용되는 유일한 조합은 PublicStatic입니다.

callingConvention
CallingConventions

동적 메서드의 호출 규칙입니다. Standard이어야 합니다.

returnType
Type

동적 메서드의 반환 형식을 지정하는 Type 개체이거나, 메서드에 반환 형식이 없으면 null입니다.

parameterTypes
Type[]

동적 메서드의 매개 변수 형식을 지정하는 Type 개체의 배열이거나, 메서드에 매개 변수가 없으면 null입니다.

owner
Type

동적 메서드가 논리적으로 연결되는 Type 입니다. 동적 메서드에 해당 형식의 모든 멤버에 대한 액세스 권한이 있습니다.

skipVisibility
Boolean

동적 메서드의 MSIL에서 액세스하는 형식 및 멤버에서 JIT 표시 유형 확인을 건너뛰는 경우true 이고, 그러지 않으면 false입니다.

예외

parameterTypes의 요소는 null 또는 Void입니다.

또는

owner 가 인터페이스, 배열, 개방형 제네릭 형식, 제네릭 형식 또는 메서드의 형식 매개 변수입니다.

name이(가) null인 경우

또는

owner이(가) null인 경우

attributesPublicStatic이외의 플래그 조합입니다.

또는

callingConventionStandard가 아닙니다.

또는

returnTypeIsByReftrue를 반환하는 형식입니다.

설명

동적 메서드는 형식 owner이 포함된 모듈에 전역입니다. 형식의 모든 멤버에 액세스할 수 있습니다 owner.

이 생성자를 사용하여 만든 동적 메서드는 형식 owner의 모든 멤버에 액세스할 수 있으며 를 포함하는 모듈에 포함된 모든 형식의 public 및 internal (Friend Visual Basic의 경우) 멤버에 액세스할 수 있습니다 owner. JIT 컴파일러의 표시 유형 검사를 건너뛰면 동적 메서드가 다른 모든 형식의 프라이빗 및 보호된 멤버에도 액세스할 수 있습니다. 예를 들어 개체를 직렬화하는 코드를 작성할 때 유용합니다.

참고

이전 버전과의 호환성을 위해 이 생성자는 다음 조건이 모두 true owner 인 경우 플래그를 SecurityPermissionFlag.ControlEvidence 요구 SecurityPermission 합니다. 가 호출 모듈 이외의 모듈에 있고 플래그에 대한 ReflectionPermissionReflectionPermissionFlag.MemberAccess 요구가 실패했습니다. 에 대한 SecurityPermission 수요가 성공하면 작업이 허용됩니다.

추가 정보

적용 대상