ConstructorBuilder.SetImplementationFlags(MethodImplAttributes) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
이 생성자에 대한 메서드 구현 플래그를 설정합니다.
public:
void SetImplementationFlags(System::Reflection::MethodImplAttributes attributes);
public void SetImplementationFlags (System.Reflection.MethodImplAttributes attributes);
member this.SetImplementationFlags : System.Reflection.MethodImplAttributes -> unit
Public Sub SetImplementationFlags (attributes As MethodImplAttributes)
매개 변수
- attributes
- MethodImplAttributes
메서드 구현 플래그입니다.
예외
포함하는 형식을 CreateType()을 사용하여 만들었습니다.
설명
다음 코드 샘플에서는 의 SetImplementationFlags
사용을 보여 줍니다.
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", true );
FieldInfo^ myFieldInfo2 = myModuleBuilder->DefineUninitializedData( "myField", 2, FieldAttributes::Public );
// 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^ myConstructor = myTypeBuilder->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, myConstructorArgs );
// Set the method implementation flags for the constructor.
myConstructor->SetImplementationFlags( static_cast<MethodImplAttributes>(MethodImplAttributes::PreserveSig | MethodImplAttributes::Runtime) );
// Get the method implementation flags for the constructor.
MethodImplAttributes myMethodAttributes = myConstructor->GetMethodImplementationFlags();
Type^ myAttributeType = MethodImplAttributes::typeid;
int myAttribValue = (int)myMethodAttributes;
if ( !myAttributeType->IsEnum )
{
Console::WriteLine( "This is not an Enum" );
}
// Display the field info names of the retrieved method implementation flags.
array<FieldInfo^>^myFieldInfo = myAttributeType->GetFields( static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Static) );
Console::WriteLine( "The Field info names of the MethodImplAttributes for the constructor are:" );
for ( int i = 0; i < myFieldInfo->Length; i++ )
{
int myFieldValue = *safe_cast<Int32^>(myFieldInfo[ i ]->GetValue( nullptr ));
if ( (myFieldValue & myAttribValue) == myFieldValue )
{
Console::WriteLine( " {0}", myFieldInfo[ i ]->Name );
}
}
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", true);
FieldInfo myFieldInfo2 =
myModuleBuilder.DefineUninitializedData("myField", 2, FieldAttributes.Public);
// 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 myConstructor = myTypeBuilder.DefineConstructor(
MethodAttributes.Public, CallingConventions.Standard, myConstructorArgs);
// Set the method implementation flags for the constructor.
myConstructor.SetImplementationFlags(MethodImplAttributes.PreserveSig | MethodImplAttributes.Runtime);
// Get the method implementation flags for the constructor.
MethodImplAttributes myMethodAttributes = myConstructor.GetMethodImplementationFlags();
Type myAttributeType = typeof(MethodImplAttributes);
int myAttribValue = (int) myMethodAttributes;
if(! myAttributeType.IsEnum)
{
Console.WriteLine("This is not an Enum");
}
// Display the field info names of the retrieved method implementation flags.
FieldInfo[] myFieldInfo = myAttributeType.GetFields(BindingFlags.Public | BindingFlags.Static);
Console.WriteLine("The Field info names of the MethodImplAttributes for the constructor are:");
for (int i = 0; i < myFieldInfo.Length; i++)
{
int myFieldValue = (Int32)myFieldInfo[i].GetValue(null);
if ((myFieldValue & myAttribValue) == myFieldValue)
{
Console.WriteLine(" " + myFieldInfo[i].Name);
}
}
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", True)
Dim myFieldInfo2 As FieldInfo = myModuleBuilder.DefineUninitializedData _
("myField", 2, FieldAttributes.Public)
' 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 myConstructor As ConstructorBuilder = myTypeBuilder.DefineConstructor _
(MethodAttributes.Public, CallingConventions.Standard, myConstructorArgs)
' Set the method implementation flags for the constructor.
myConstructor.SetImplementationFlags(MethodImplAttributes.PreserveSig Or _
MethodImplAttributes.Runtime)
' Get the method implementation flags for the constructor.
Dim myMethodAttributes As MethodImplAttributes = myConstructor.GetMethodImplementationFlags()
Dim myAttributeType As Type = GetType(MethodImplAttributes)
Dim myAttribValue As Integer = CInt(myMethodAttributes)
If Not myAttributeType.IsEnum Then
Console.WriteLine("This is not an Enum")
End If
' Display the field info names of the retrieved method implementation flags.
Dim myFieldInfo As FieldInfo() = myAttributeType.GetFields(BindingFlags.Public Or _
BindingFlags.Static)
Console.WriteLine("The Field info names of the MethodImplAttributes for the constructor are:")
Dim i As Integer
For i = 0 To myFieldInfo.Length - 1
Dim myFieldValue As Integer = CType(myFieldInfo(i).GetValue(Nothing), Int32)
If(myFieldValue And myAttribValue) = myFieldValue Then
Console.WriteLine(" " + myFieldInfo(i).Name)
End If
Next i
적용 대상
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET