PropertyBuilder::SetGetMethod Method (MethodBuilder^)

 

Sets the method that gets the property value.

Namespace:   System.Reflection.Emit
Assembly:  mscorlib (in mscorlib.dll)

public:
void SetGetMethod(
	MethodBuilder^ mdBuilder
)

Parameters

mdBuilder
Type: System.Reflection.Emit::MethodBuilder^

A MethodBuilder object that represents the method that gets the property value.

Exception Condition
ArgumentNullException

mdBuilder is null.

InvalidOperationException

CreateType has been called on the enclosing type.

The following code sample demonstrates how to attach a dynamic method to a get property created with PropertyBuilder using SetGetMethod.

// 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 );

.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Return to top
Show: