Table of Contents

Class ReflectionUtilities

Namespace
PolyType.Utilities
Assembly
PolyType.dll

Defines a set of common reflection utilities for use by PolyType applications.

public static class ReflectionUtilities
Inheritance
ReflectionUtilities
Inherited Members

Methods

GetCustomAttribute<TAttribute>(ICustomAttributeProvider, bool)

Looks up the specified attribute provider for an attribute of the given type.

public static TAttribute? GetCustomAttribute<TAttribute>(this ICustomAttributeProvider attributeProvider, bool inherit = false) where TAttribute : Attribute

Parameters

attributeProvider ICustomAttributeProvider

The custom attribute provider to look up from.

inherit bool

Whether to look for inherited attributes.

Returns

TAttribute

The first occurrence of the attribute if found, or null otherwise.

Type Parameters

TAttribute

The attribute type to attempt to look up.

GetCustomAttributes<TAttribute>(ICustomAttributeProvider, bool)

Looks up the specified attribute provider for attributes of the given type.

public static IEnumerable<TAttribute> GetCustomAttributes<TAttribute>(this ICustomAttributeProvider attributeProvider, bool inherit = false) where TAttribute : Attribute

Parameters

attributeProvider ICustomAttributeProvider

The custom attribute provider to look up from.

inherit bool

Whether to look for inherited attributes.

Returns

IEnumerable<TAttribute>

An enumerable containing all instances of the attribute defined on the attribute provider.

Type Parameters

TAttribute

The attribute type to attempt to look up.

GetDerivedTypeShapeName(Type)

Returns a name suitable for auto-deriving DerivedTypeShapeAttribute.Name that includes type arguments separated by underscores.

public static string GetDerivedTypeShapeName(Type type)

Parameters

type Type

The type to format.

Returns

string

The formatted name with type arguments separated by underscores.

Remarks

Examples:

  • Cow<SolidHoof> → Cow_SolidHoof
  • Cow<List<SolidHoof>> → Cow_List_SolidHoof

IsDefined<TAttribute>(ICustomAttributeProvider, bool)

Determines if the specified attribute is defined by the attribute provider.

public static bool IsDefined<TAttribute>(this ICustomAttributeProvider attributeProvider, bool inherit = false) where TAttribute : Attribute

Parameters

attributeProvider ICustomAttributeProvider

The custom attribute provider to look up from.

inherit bool

Whether to look for inherited attributes.

Returns

bool

true is the attribute is defined, or false otherwise.

Type Parameters

TAttribute

The attribute type to attempt to look up.