本文整理汇总了C#中System.Reflection.Emit.ConstructorBuilder.SetImplementationFlags方法的典型用法代码示例。如果您正苦于以下问题:C# ConstructorBuilder.SetImplementationFlags方法的具体用法?C# ConstructorBuilder.SetImplementationFlags怎么用?C# ConstructorBuilder.SetImplementationFlags使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.ConstructorBuilder
的用法示例。
在下文中一共展示了ConstructorBuilder.SetImplementationFlags方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssemblyName
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);
}
}