PostSharpAPI ReferencePost­Sharp.​ReflectionReflection­SearchGet­Custom­Attributes­On­Target
Open sandboxFocus

ReflectionSearch.GetCustomAttributesOnTarget Method

GetCustomAttributesOnTarget(Object)

Gets all custom attributes on a given element of code, including those who have been added indirectly, for instance through MulticastAttribute.

Declaration
public static CustomAttributeInstance[] GetCustomAttributesOnTarget(object target)
Parameters
Type Name Description
Object target

Element of code (System.Type, MethodInfo, ...) whose custom attributes are requested.

Returns
Type Description
CustomAttributeInstance[]

The set of all custom attributes added, directly or indirectly, to target.

Remarks

note

This method returns custom attributes from the internal annotation repository of PostSharp. This repository contains more than only custom attributes added in source code. For instance, if you use MulticastAttribute to add a custom attribute to several elements of code in a single line of code, this method will return one custom attribute instance for every target of the MulticastAttribute .

note

This feature is available only at build time.

GetCustomAttributesOnTarget(Object, ReflectionSearchOptions)

Gets all custom attributes on a given element of code, including those who have been added indirectly, for instance through MulticastAttribute.

Declaration
public static CustomAttributeInstance[] GetCustomAttributesOnTarget(object target, ReflectionSearchOptions options)
Parameters
Type Name Description
Object target

Element of code (System.Type, MethodInfo, ...) whose custom attributes are requested.

ReflectionSearchOptions options

This parameter has no effect and is kept only for backwards compatibility.

Returns
Type Description
CustomAttributeInstance[]

The set of all custom attributes added, directly or indirectly, to target.

Remarks

note

This method returns custom attributes from the internal annotation repository of PostSharp. This repository contains more than only custom attributes added in source code. For instance, if you use MulticastAttribute to add a custom attribute to several elements of code in a single line of code, this method will return one custom attribute instance for every target of the MulticastAttribute .

note

This feature is available only at build time.

GetCustomAttributesOnTarget<T>(Object, ReflectionSearchOptions)

Gets all custom attributes of a given type on a given element of code, including those who have been added indirectly, for instance through MulticastAttribute and specifies additional options.

Declaration
public static IList<T> GetCustomAttributesOnTarget<T>(object target, ReflectionSearchOptions options)
where T : Attribute
Parameters
Type Name Description
Object target

Element of code (System.Type, MethodInfo, ...) whose custom attributes are requested.

ReflectionSearchOptions options

IncludeDerivedTypes or None.

Returns
Type Description
IList<T>

The set of all custom attributes added, directly or indirectly, to target.

Type Parameters
Name Description
T

Type of the custom attribute.

Remarks

note

This method returns custom attributes from the internal annotation repository of PostSharp. This repository contains more than only custom attributes added in source code. For instance, if you use MulticastAttribute to add a custom attribute to several elements of code in a single line of code, this method will return one custom attribute instance for every target of the MulticastAttribute .

note

This feature is available only at build time.