CustomAttributeNamedArgument Structure
TOC
Collapse the table of content
Expand the table of content

CustomAttributeNamedArgument Structure

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Represents a named argument of a custom attribute in the reflection-only context.

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

public struct CustomAttributeNamedArgument

The CustomAttributeNamedArgument type exposes the following members.

  NameDescription
Public propertyIsFieldGets a value that indicates whether the named argument is a field.
Public propertyMemberNameGets the name of the attribute member that would be used to set the named argument.
Public propertyTypedValueGets a CustomAttributeTypedArgument structure that can be used to obtain the type and value of the current named argument.
Top

  NameDescription
Public methodEqualsIndicates whether this instance and a specified object are equal. (Inherited from ValueType.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeReturns the hash code for this instance. (Inherited from ValueType.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns the fully qualified type name of this instance. (Inherited from ValueType.)
Top

Code that is being examined in the reflection-only context cannot be executed, so it is not always possible to examine custom attributes by creating instances of them and then examining their properties, using methods like Attribute.GetCustomAttributes, MemberInfo.GetCustomAttributes, and so on. If the code for the attribute type itself is loaded into the reflection-only context, it cannot be executed.

The CustomAttributeNamedArgument structure is used by the CustomAttributeData class to provide access to a named argument specified for a custom attribute instance, without executing the code of the corresponding property of the custom attribute type. The TypedValue property returns a CustomAttributeTypedArgument structure that contains the type and value of the named argument.

Important noteImportant Note:

Whether an argument is named or positional, you must access its type and value by using the CustomAttributeTypedArgument structure.

To create instances of the CustomAttributeData class, use the staticGetCustomAttributes() factory method.

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 information about the custom attributes that were applied to it and to the type and members it contains.

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

Windows Phone OS

Supported in: 8.1, 8.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Show:
© 2016 Microsoft