ConstructorBuilder.GetMethodImplementationFlags 方法

返回此构造函数的方法实现标志。

**命名空间:**System.Reflection.Emit
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public Overrides Function GetMethodImplementationFlags As MethodImplAttributes
用法
Dim instance As ConstructorBuilder
Dim returnValue As MethodImplAttributes

returnValue = instance.GetMethodImplementationFlags
public override MethodImplAttributes GetMethodImplementationFlags ()
public:
virtual MethodImplAttributes GetMethodImplementationFlags () override
public MethodImplAttributes GetMethodImplementationFlags ()
public override function GetMethodImplementationFlags () : MethodImplAttributes

返回值

此构造函数的方法实现标志。

备注

下面的代码阐释了如何使用 GetMethodImplementationFlags

Dim myMethodBuilder As MethodBuilder = Nothing
Dim myCurrentDomain As AppDomain = AppDomain.CurrentDomain
' Create assembly in current CurrentDomain.
Dim myAssemblyName As New AssemblyName()
myAssemblyName.Name = "TempAssembly"
' Create a dynamic assembly.
myAssemblyBuilder = _ 
          myCurrentDomain.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.Run)
' Create a dynamic module in the assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule")
' Create a type in the module.
Dim myTypeBuilder As TypeBuilder = _ 
             myModuleBuilder.DefineType("TempClass", TypeAttributes.Public)
Dim myGreetingField As FieldBuilder = _ 
         myTypeBuilder.DefineField("Greeting", GetType(String), FieldAttributes.Public)
 Dim myConstructorArgs As Type() = {GetType(String)}
' Define a constructor of the dynamic class.
Dim myConstructorBuilder As ConstructorBuilder = _ 
    myTypeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, _ 
                                    myConstructorArgs)
' Get a reference to the module that contains this constructor.
Dim myModule As [Module] = myConstructorBuilder.GetModule()
Console.WriteLine("Module Name : " + myModule.Name)
' Get the 'MethodToken' that represents the token for this constructor.
Dim myMethodToken As MethodToken = myConstructorBuilder.GetToken()
Console.WriteLine("Constructor Token is : " + myMethodToken.Token.ToString())
' Get the method implementation flags for this constructor.
Dim myMethodImplAttributes As MethodImplAttributes = _
    myConstructorBuilder.GetMethodImplementationFlags()
Console.WriteLine("MethodImplAttributes : " + myMethodImplAttributes.ToString())
MethodBuilder myMethodBuilder = null;
AppDomain myCurrentDomain = AppDomain.CurrentDomain;
// Create assembly in current CurrentDomain.
AssemblyName myAssemblyName = new AssemblyName();
myAssemblyName.Name = "TempAssembly";
// Create a dynamic assembly.
myAssemblyBuilder = myCurrentDomain.DefineDynamicAssembly
                              (myAssemblyName, AssemblyBuilderAccess.Run);
// Create a dynamic module in the assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule");
// Create a type in the module.
TypeBuilder myTypeBuilder = myModuleBuilder.DefineType("TempClass",TypeAttributes.Public);
FieldBuilder myGreetingField = myTypeBuilder.DefineField("Greeting",
   typeof(String), FieldAttributes.Public);
Type[] myConstructorArgs = { typeof(String) };
// Define a constructor of the dynamic class.
ConstructorBuilder myConstructorBuilder = myTypeBuilder.DefineConstructor(
   MethodAttributes.Public, CallingConventions.Standard, myConstructorArgs);
// Get a reference to the module that contains this constructor.
Module myModule = myConstructorBuilder.GetModule();
Console.WriteLine("Module Name : " + myModule.Name);
// Get the 'MethodToken' that represents the token for this constructor.
MethodToken myMethodToken = myConstructorBuilder.GetToken();
Console.WriteLine("Constructor Token is : " + myMethodToken.Token);
// Get the method implementation flags for this constructor.
MethodImplAttributes myMethodImplAttributes = myConstructorBuilder.GetMethodImplementationFlags();
Console.WriteLine("MethodImplAttributes : "  + myMethodImplAttributes);
MethodBuilder^ myMethodBuilder = nullptr;
AppDomain^ myCurrentDomain = AppDomain::CurrentDomain;
// Create assembly in current CurrentDomain.
AssemblyName^ myAssemblyName = gcnew AssemblyName;
myAssemblyName->Name = "TempAssembly";
// Create a dynamic assembly.
myAssemblyBuilder = myCurrentDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run );
// Create a dynamic module in the assembly.
myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule" );
// Create a type in the module.
TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "TempClass", TypeAttributes::Public );
FieldBuilder^ myGreetingField = myTypeBuilder->DefineField( "Greeting",
   String::typeid, FieldAttributes::Public );
array<Type^>^myConstructorArgs = {String::typeid};
// Define a constructor of the dynamic class.
ConstructorBuilder^ myConstructorBuilder = myTypeBuilder->DefineConstructor(
   MethodAttributes::Public, CallingConventions::Standard, myConstructorArgs );
// Get a reference to the module that contains this constructor.
Module^ myModule = myConstructorBuilder->GetModule();
Console::WriteLine( "Module Name : {0}", myModule->Name );
// Get the 'MethodToken' that represents the token for this constructor.
MethodToken myMethodToken = myConstructorBuilder->GetToken();
Console::WriteLine( "Constructor Token is : {0}", myMethodToken.Token );
// Get the method implementation flags for this constructor.
MethodImplAttributes myMethodImplAttributes = myConstructorBuilder->GetMethodImplementationFlags();
Console::WriteLine( "MethodImplAttributes : {0}", myMethodImplAttributes );
MethodBuilder myMethodBuilder = null;
AppDomain myCurrentDomain = AppDomain.get_CurrentDomain();

// Create assembly in current CurrentDomain.
AssemblyName myAssemblyName = new AssemblyName();

myAssemblyName.set_Name("TempAssembly");

// Create a dynamic assembly.
myAssemblyBuilder =
    myCurrentDomain.DefineDynamicAssembly(myAssemblyName,
    AssemblyBuilderAccess.Run);

// Create a dynamic module in the assembly.
myModuleBuilder =
    myAssemblyBuilder.DefineDynamicModule("TempModule");

// Create a type in the module.
TypeBuilder myTypeBuilder =
    myModuleBuilder.DefineType("TempClass", TypeAttributes.Public);
FieldBuilder myGreetingField =
    myTypeBuilder.DefineField("Greeting", String.class.ToType(),
    FieldAttributes.Public);
Type myConstructorArgs[] = { String.class.ToType() };
// Define a constructor of the dynamic class.
ConstructorBuilder myConstructorBuilder =
    myTypeBuilder.DefineConstructor(MethodAttributes.Public,
    CallingConventions.Standard, myConstructorArgs);

// Get a reference to the module that contains this constructor.
Module myModule = myConstructorBuilder.GetModule();
Console.WriteLine("Module Name : " + myModule.get_Name());

// Get the 'MethodToken' that represents the token for this constructor.
MethodToken myMethodToken = myConstructorBuilder.GetToken();
Console.WriteLine("Constructor Token is : " + myMethodToken.get_Token());

// Get the method implementation flags for this constructor.
MethodImplAttributes myMethodImplAttributes =
    myConstructorBuilder.GetMethodImplementationFlags();
Console.WriteLine("MethodImplAttributes : " + myMethodImplAttributes);

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

ConstructorBuilder 类
ConstructorBuilder 成员
System.Reflection.Emit 命名空间