MethodBodyBlock 클래스

정의

ECMA 335 어셈블리의 메서드 본문을 나타냅니다.

public ref class MethodBodyBlock sealed
public sealed class MethodBodyBlock
type MethodBodyBlock = class
Public NotInheritable Class MethodBodyBlock
상속
MethodBodyBlock

예제

이 예제에서는 지정된 형식 정의 및 표시 메서드 본문 정보의 모든 메서드에 대한 메서드 본문을 읽는 방법을 보여 줍니다.

static void PrintMethods(PEReader reader, MetadataReader mr, TypeDefinition tdef)
{
    MethodDefinitionHandleCollection methods = tdef.GetMethods();

    foreach (MethodDefinitionHandle mdefh in methods)
    {
        MethodDefinition mdef = mr.GetMethodDefinition(mdefh);
        string mname = mr.GetString(mdef.Name);
        Console.WriteLine($"Method: {mname}");

        // Get the relative address of the method body in the executable
        int rva = mdef.RelativeVirtualAddress;

        if (rva == 0)
        {
            Console.WriteLine("Method body not found");
            Console.WriteLine();
            continue;
        }

        // Get method body information
        MethodBodyBlock mb = reader.GetMethodBody(rva);
        Console.WriteLine($"  Maximum stack size: {mb.MaxStack}");
        Console.WriteLine($"  Local variables initialized: {mb.LocalVariablesInitialized}");

        byte[]? il = mb.GetILBytes();
        Console.WriteLine($"  Method body size: {il?.Length ?? 0}");
        Console.WriteLine($"  Exception regions: {mb.ExceptionRegions.Length}");
        Console.WriteLine();

        foreach (var region in mb.ExceptionRegions)
        {
            Console.WriteLine(region.Kind.ToString());
            Console.WriteLine($"  Try block offset: {region.TryOffset}");
            Console.WriteLine($"  Try block length: {region.TryLength}");
            Console.WriteLine($"  Handler offset: {region.HandlerOffset}");
            Console.WriteLine($"  Handler length: {region.HandlerLength}");
            Console.WriteLine();
        }
    }
}

설명

메서드 본문에는 메서드를 구성하는 CIL(Common Intermediate Language) 명령과 해당 지역 변수 및 예외 지역에 대한 정보가 포함되어 있습니다. 메서드를 GetMethodBody 사용하여 지정된 메서드에 MethodBodyBlock 대한 instance 가져올 수 있습니다.

CIL 명령 및 메타데이터의 형식은 ECMA-335 사양에 의해 정의됩니다. 자세한 내용은 Ecma International 웹 사이트의 표준 ECMA-335 - CLI(공용 언어 인프라) 를 참조하세요.

속성

ExceptionRegions

이 메서드 본문에 있는 예외 영역의 배열을 가져옵니다.

LocalSignature

지역 변수 서명에 대한 핸들을 가져옵니다.

LocalVariablesInitialized

이 메서드의 지역 변수가 해당 형식의 기본값으로 초기화되는지 여부를 나타내는 값을 가져옵니다.

MaxStack

이 메서드에 대한 평가 스택의 최대 항목 수를 가져옵니다.

Size

헤더, IL 및 예외 영역을 포함하여 메서드 본문의 크기를 가져옵니다.

메서드

Create(BlobReader)

지정된 Blob 판독기를 사용하여 클래스의 MethodBodyBlock 새 instance 만듭니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetILBytes()

이 메서드 본문의 IL 바이트 코드를 바이트 배열로 가져옵니다.

GetILContent()

이 메서드 본문의 IL 바이트코드를 변경할 수 없는 배열로 가져옵니다.

GetILReader()

이 메서드 본문의 IL 바이트 코드를 읽는 Blob 판독기를 가져옵니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상