MethodBuilder.SetCustomAttribute Method

Definition

Sets a custom attribute.

Overloads

SetCustomAttribute(CustomAttributeBuilder)

Sets a custom attribute using a custom attribute builder.

SetCustomAttribute(ConstructorInfo, Byte[])

Sets a custom attribute using a specified custom attribute blob.

SetCustomAttribute(CustomAttributeBuilder)

Source:
MethodBuilder.cs
Source:
MethodBuilder.cs
Source:
MethodBuilder.cs

Sets a custom attribute using a custom attribute builder.

C#
public void SetCustomAttribute(System.Reflection.Emit.CustomAttributeBuilder customBuilder);

Parameters

customBuilder
CustomAttributeBuilder

An instance of a helper class to describe the custom attribute.

Exceptions

customBuilder is null.

For the current method, the IsGenericMethod property is true, but the IsGenericMethodDefinition property is false.

Remarks

The SetCustomAttribute method can interact with the SetImplementationFlags method when the two methods are used in combination. See the Remarks section of the SetImplementationFlags method for details.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1

SetCustomAttribute(ConstructorInfo, Byte[])

Source:
MethodBuilder.cs
Source:
MethodBuilder.cs
Source:
MethodBuilder.cs

Sets a custom attribute using a specified custom attribute blob.

C#
public void SetCustomAttribute(System.Reflection.ConstructorInfo con, byte[] binaryAttribute);
C#
[System.Runtime.InteropServices.ComVisible(true)]
public void SetCustomAttribute(System.Reflection.ConstructorInfo con, byte[] binaryAttribute);

Parameters

con
ConstructorInfo

The constructor for the custom attribute.

binaryAttribute
Byte[]

A byte blob representing the attributes.

Attributes

Exceptions

con or binaryAttribute is null.

For the current method, the IsGenericMethod property is true, but the IsGenericMethodDefinition property is false.

Remarks

For information on how to format binaryAttribute, see the metadata specification in Partition II of the Common Language Infrastructure (CLI) specification.

The SetCustomAttribute method can interact with the SetImplementationFlags method when the two methods are used in combination. See the Remarks section of the SetImplementationFlags method for details.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1