The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
PropertyBuilder::SetGetMethod Method (MethodBuilder^)
.NET Framework (current version)
Sets the method that gets the property value.
Assembly: mscorlib (in mscorlib.dll)
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
Available since 1.1
Silverlight
Available since 2.0
Show: