Skip to content

M_CodeJam_Reflection_ReflectionExtensions_TryGetMetadataAttribute__1

Andrew Koryavchenko edited this page Jul 4, 2017 · 2 revisions

ReflectionExtensions.TryGetMetadataAttribute(TAttribute) Method (ICustomAttributeProvider)

Performs search for metadata attribute. 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: 1.1.0.0 (1.1.0.0)

Syntax

C#

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

VB

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

F#

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

Parameters

 

attributeProvider
Type: System.Reflection.ICustomAttributeProvider
Metadata attribute source.

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