TypeBuilder.SetCustomAttribute 方法

定義

設定自訂屬性。Sets a custom attribute.

多載

SetCustomAttribute(CustomAttributeBuilder)

使用自訂屬性產生器來設定自訂屬性。Set a custom attribute using a custom attribute builder.

SetCustomAttribute(ConstructorInfo, Byte[])

使用指定的自訂屬性 Blob 來設定自訂屬性。Sets a custom attribute using a specified custom attribute blob.

SetCustomAttribute(CustomAttributeBuilder)

使用自訂屬性產生器來設定自訂屬性。Set a custom attribute using a custom attribute builder.

public:
 void SetCustomAttribute(System::Reflection::Emit::CustomAttributeBuilder ^ customBuilder);
public void SetCustomAttribute (System.Reflection.Emit.CustomAttributeBuilder customBuilder);
member this.SetCustomAttribute : System.Reflection.Emit.CustomAttributeBuilder -> unit
Public Sub SetCustomAttribute (customBuilder As CustomAttributeBuilder)

參數

customBuilder
CustomAttributeBuilder

定義自訂屬性的協助程式類別執行個體。An instance of a helper class to define the custom attribute.

例外狀況

customBuildernullcustomBuilder is null.

目前動態類型的 IsGenericType 屬性為 true,但 IsGenericTypeDefinition 屬性為 falseFor the current dynamic type, the IsGenericType property is true, but the IsGenericTypeDefinition property is false.

備註

注意

從 .NET Framework 2.0 Service Pack 1 開始,此成員不再需要 ReflectionPermission 使用 ReflectionPermissionFlag.ReflectionEmit 旗標。Starting with the .NET Framework 2.0 Service Pack 1, this member no longer requires ReflectionPermission with the ReflectionPermissionFlag.ReflectionEmit flag. (查看 反映發出中的安全性問題。 ) 若要使用此功能,您的應用程式應以 .NET Framework 3.5 或更新版本為目標。(See Security Issues in Reflection Emit.) To use this functionality, your application should target the .NET Framework 3.5 or later.

適用於

SetCustomAttribute(ConstructorInfo, Byte[])

使用指定的自訂屬性 Blob 來設定自訂屬性。Sets a custom attribute using a specified custom attribute blob.

public:
 void SetCustomAttribute(System::Reflection::ConstructorInfo ^ con, cli::array <System::Byte> ^ binaryAttribute);
public void SetCustomAttribute (System.Reflection.ConstructorInfo con, byte[] binaryAttribute);
[System.Runtime.InteropServices.ComVisible(true)]
public void SetCustomAttribute (System.Reflection.ConstructorInfo con, byte[] binaryAttribute);
member this.SetCustomAttribute : System.Reflection.ConstructorInfo * byte[] -> unit
[<System.Runtime.InteropServices.ComVisible(true)>]
member this.SetCustomAttribute : System.Reflection.ConstructorInfo * byte[] -> unit
Public Sub SetCustomAttribute (con As ConstructorInfo, binaryAttribute As Byte())

參數

con
ConstructorInfo

自訂屬性的建構函式。The constructor for the custom attribute.

binaryAttribute
Byte[]

代表屬性的位元組 Blob。A byte blob representing the attributes.

屬性

例外狀況

conbinaryAttributenullcon or binaryAttribute is null.

目前動態類型的 IsGenericType 屬性為 true,但 IsGenericTypeDefinition 屬性為 falseFor the current dynamic type, the IsGenericType property is true, but the IsGenericTypeDefinition property is false.

備註

如需有關如何格式化的詳細資訊 binaryAttribute ,請參閱 ECMA c # 和通用語言基礎結構標準 以及 標準 ECMA-335-通用語言基礎結構 (CLI) For more information on how to format binaryAttribute, see ECMA C# and Common Language Infrastructure Standards and Standard ECMA-335 - Common Language Infrastructure (CLI).

注意

從 .NET Framework 2.0 Service Pack 1 開始,此成員不再需要 ReflectionPermission 使用 ReflectionPermissionFlag.ReflectionEmit 旗標。Starting with the .NET Framework 2.0 Service Pack 1, this member no longer requires ReflectionPermission with the ReflectionPermissionFlag.ReflectionEmit flag. (查看 反映發出中的安全性問題。 ) 若要使用此功能,您的應用程式應以 .NET Framework 3.5 或更新版本為目標。(See Security Issues in Reflection Emit.) To use this functionality, your application should target the .NET Framework 3.5 or later.

適用於