다음을 통해 공유


PropertyBuilder.SetGetMethod(MethodBuilder) 메서드

정의

속성 값을 가져오는 메서드를 설정합니다.

public:
 void SetGetMethod(System::Reflection::Emit::MethodBuilder ^ mdBuilder);
public void SetGetMethod (System.Reflection.Emit.MethodBuilder mdBuilder);
member this.SetGetMethod : System.Reflection.Emit.MethodBuilder -> unit
Public Sub SetGetMethod (mdBuilder As MethodBuilder)

매개 변수

mdBuilder
MethodBuilder

속성 값을 가져오는 메서드를 나타내는 MethodBuilder 개체입니다.

예외

mdBuilder이(가) null인 경우

바깥쪽 형식에서 CreateType()을 호출한 경우

예제

다음 코드 샘플에서는 를 사용하여 SetGetMethod만든 PropertyBuilder 속성에 동적 메서드를 get 연결하는 방법을 보여 줍니다.

// Define property Greeting.
PropertyBuilder^ greetingPropertyBuilder = helloWorldTypeBuilder->DefineProperty( "Greeting", PropertyAttributes::None, String::typeid, nullptr );

// Define the 'get_Greeting' method.
MethodBuilder^ getGreetingMethod = helloWorldTypeBuilder->DefineMethod( "get_Greeting", static_cast<MethodAttributes>(MethodAttributes::Public | MethodAttributes::HideBySig | MethodAttributes::SpecialName), String::typeid, nullptr );

// Generate IL code for 'get_Greeting' method.
ILGenerator^ methodIL = getGreetingMethod->GetILGenerator();
methodIL->Emit( OpCodes::Ldarg_0 );
methodIL->Emit( OpCodes::Ldfld, greetingFieldBuilder );
methodIL->Emit( OpCodes::Ret );
greetingPropertyBuilder->SetGetMethod( getGreetingMethod );
// Define property Greeting.
PropertyBuilder greetingPropertyBuilder = helloWorldTypeBuilder.DefineProperty(
                         "Greeting",PropertyAttributes.None,typeof(string),null);

// Define the 'get_Greeting' method.
MethodBuilder getGreetingMethod = helloWorldTypeBuilder.DefineMethod("get_Greeting",
   MethodAttributes.Public|MethodAttributes.HideBySig|MethodAttributes.SpecialName,
   typeof(String),null);
// Generate IL code for 'get_Greeting' method.
ILGenerator methodIL = getGreetingMethod.GetILGenerator();
methodIL.Emit(OpCodes.Ldarg_0);
methodIL.Emit(OpCodes.Ldfld, greetingFieldBuilder);
methodIL.Emit(OpCodes.Ret);
greetingPropertyBuilder.SetGetMethod(getGreetingMethod);
' Define property Greeting.
Dim greetingPropertyBuilder As PropertyBuilder = helloWorldTypeBuilder.DefineProperty _
                           ("Greeting", PropertyAttributes.None, GetType(String), Nothing)

' Define the 'get_Greeting' method.
Dim getGreetingMethod As MethodBuilder = helloWorldTypeBuilder.DefineMethod("get_Greeting", _
                        MethodAttributes.Public Or MethodAttributes.HideBySig Or _
                        MethodAttributes.SpecialName, GetType(String), Nothing)
' Generate IL code for 'get_Greeting' method.
Dim methodIL As ILGenerator = getGreetingMethod.GetILGenerator()
methodIL.Emit(OpCodes.Ldarg_0)
methodIL.Emit(OpCodes.Ldfld, greetingFieldBuilder)
methodIL.Emit(OpCodes.Ret)
greetingPropertyBuilder.SetGetMethod(getGreetingMethod)

적용 대상