CustomAttributeData.Constructor Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets a ConstructorInfo object that represents the constructor that would have initialized the custom attribute.

Namespace:   System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

abstract Constructor : ConstructorInfo with get
override Constructor : ConstructorInfo with get

Property Value

Type: System.Reflection.ConstructorInfo

An object that represents the constructor that would have initialized the custom attribute represented by the current instance of the CustomAttributeData class.

If an attribute type has multiple constructors, this property returns only the particular constructor that would have initialized the attribute instance represented by the current CustomAttributeData object.

The following example defines a custom attribute with four constructors and four properties. Two of the properties are read-only, and are set by using the positional parameters of the constructors. The other two properties are read/write, and can be set only by using named arguments. One positional property is an array of strings, and one named property is an array of integers.

The attribute is applied to the assembly, to a type declared in the assembly, to a method of the type, and to a parameter of the method. Different constructors are used for these cases. When executed, the assembly loads itself into the reflection-only context and displays the custom attributes.

The attribute that is applied to the type demonstrates array properties, with both positional and named arguments.

The Constructor property is used in the ShowAttributeData method that displays custom attribute data. In this code example, the ConstructorInfo returned by this property is used to display a text string that describes the constructor, demonstrating that the property returns the constructor that would initialize the attribute.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top