Class ReflectionUtilities
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
attributeProviderICustomAttributeProviderThe custom attribute provider to look up from.
inheritboolWhether to look for inherited attributes.
Returns
- TAttribute
The first occurrence of the attribute if found, or null otherwise.
Type Parameters
TAttributeThe 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
attributeProviderICustomAttributeProviderThe custom attribute provider to look up from.
inheritboolWhether to look for inherited attributes.
Returns
- IEnumerable<TAttribute>
An enumerable containing all instances of the attribute defined on the attribute provider.
Type Parameters
TAttributeThe 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
typeTypeThe 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
attributeProviderICustomAttributeProviderThe custom attribute provider to look up from.
inheritboolWhether to look for inherited attributes.
Returns
Type Parameters
TAttributeThe attribute type to attempt to look up.