次の方法で共有


ConstructorBuilder.SetSymCustomAttribute メソッド

シンボリック情報に関連付けられたこのコンストラクタのカスタム属性を設定します。

Public Sub SetSymCustomAttribute( _
   ByVal name As String, _   ByVal data() As Byte _)
[C#]
public void SetSymCustomAttribute(stringname,byte[] data);
[C++]
public: void SetSymCustomAttribute(String* name,unsigned chardata __gc[]);
[JScript]
public function SetSymCustomAttribute(
   name : String,data : Byte[]);

パラメータ

  • name
    カスタム属性の名前。
  • data
    カスタム属性の値。

例外

例外の種類 条件
InvalidOperationException 外側の型が CreateType を使用して作成されています。

または

モジュールにシンボル ライタが定義されていません。たとえば、モジュールがデバッグ モジュールではありません。

解説

SetSymCustomAttributes の使用方法については、次のコード例を参照してください。

 
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 myFieldInfo 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)
' Display the name of the constructor.
Console.WriteLine("The constructor name is  : " + myConstructor.Name)
myConstructor.SetSymCustomAttribute("MySimAttribute", New Byte() {01, 00,00})

[C#] 
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 myFieldInfo =
   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);
// Display the name of the constructor.
Console.WriteLine("The constructor name is  : "+ myConstructor.Name);
myConstructor.SetSymCustomAttribute("MySimAttribute", new byte[]{01,00,00});

[C++] 
MethodBuilder* myMethodBuilder = 0;
AppDomain* myCurrentDomain = AppDomain::CurrentDomain;
// Create assembly in current CurrentDomain.
AssemblyName* myAssemblyName = new AssemblyName();
myAssemblyName->Name = S"TempAssembly";
// Create a dynamic assembly.
myAssemblyBuilder = myCurrentDomain->DefineDynamicAssembly
   (myAssemblyName, AssemblyBuilderAccess::Run);
// Create a dynamic module in the assembly.
myModuleBuilder = myAssemblyBuilder->DefineDynamicModule(S"TempModule",true);
FieldInfo* myFieldInfo =
   myModuleBuilder->DefineUninitializedData(S"myField", 2, FieldAttributes::Public);
// Create a type in the module.
TypeBuilder* myTypeBuilder = myModuleBuilder->DefineType(S"TempClass",TypeAttributes::Public);
FieldBuilder* myGreetingField = myTypeBuilder->DefineField(S"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);
// Display the name of the constructor.
Console::WriteLine(S"The constructor name is  : {0}", myConstructor->Name);
Byte temp0 [] = {01,00,00};
myConstructor->SetSymCustomAttribute(S"MySimAttribute", temp0);

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

ConstructorBuilder クラス | ConstructorBuilder メンバ | System.Reflection.Emit 名前空間