Skip to content

M_CodeJam_Reflection_ReflectionExtensions_TryGetMetadataAttribute__1_1

Andrew Koryavchenko edited this page Jun 17, 2018 · 2 revisions

ReflectionExtensions.TryGetMetadataAttribute(TAttribute) Method (ICustomAttributeProvider, Boolean)

Performs search for metadata attribute. If the thisLevelOnly is true, the search is performed in the following order: * member attributes, base implementation attributes (if the attributeProvider is member of the type) * type attributes, base type attributes (if the attributeProvider is type or member of the type) * container type attributes (if the type is nested type) * assembly attributes.

Namespace: CodeJam.Reflection
Assembly: CodeJam (in CodeJam.dll) Version: 2.1.0.0

Syntax

C#

public static TAttribute TryGetMetadataAttribute<TAttribute>(
	this ICustomAttributeProvider attributeProvider,
	bool thisLevelOnly
)
where TAttribute : class

VB

<ExtensionAttribute>
Public Shared Function TryGetMetadataAttribute(Of TAttribute As Class) ( 
	attributeProvider As ICustomAttributeProvider,
	thisLevelOnly As Boolean
) As TAttribute

F#

[<ExtensionAttribute>]
static member TryGetMetadataAttribute : 
        attributeProvider : ICustomAttributeProvider * 
        thisLevelOnly : bool -> 'TAttribute  when 'TAttribute : not struct

Parameters

 

attributeProvider
Type: System.Reflection.ICustomAttributeProvider
Metadata attribute source.
thisLevelOnly
Type: System.Boolean
Do not check containers for the attributes.

Type Parameters

 

TAttribute
Type of the attribute or type of the interface implemented by the attributes.

Return Value

Type: TAttribute
First attribute found.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type ICustomAttributeProvider. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

Search logic for each level matches to the GetCustomAttributes(MemberInfo, Type, Boolean) method (inherit = true). including checks of AttributeUsageAttribute. Ordering of attributes at each level is undefined and depends on runtime implementation.

See Also

Reference

ReflectionExtensions Class
TryGetMetadataAttribute Overload
CodeJam.Reflection Namespace

Clone this wiki locally