NanoByte.Common  2.8.1
NanoByte.Common.Values.AttributeUtils Class Reference

Provides helper methods for Attributes. More...

Static Public Member Functions

static IEnumerable< TAttribute > GetAttributes< TAttribute, TTarget > ()
 Gets the first TAttribute attribute set on the TTarget type. More...
 
static string GetEnumAttributeValue< TAttribute > (this Enum target, Converter< TAttribute, string > valueRetriever)
 Gets the first TAttribute attribute set on the target enum value. Then retrieves a value from the attribute using valueRetriever . More...
 
static TType ConvertFromString< TType > (this string value)
 Uses the type converter for TType (set by TypeConverterAttribute) to parse a string. More...
 
static string ConvertToString< TType > (this TType value)
 Uses the type converter for TType (set by TypeConverterAttribute) to generate a string. More...
 
static ? TValue GetAttributeValue< TAttribute, TValue > (this Assembly assembly, [InstantHandle] Func< TAttribute, TValue?> valueRetrieval)
 Retrieves a single value from a Custom Attribute associated with an Assembly. More...
 

Detailed Description

Provides helper methods for Attributes.

Member Function Documentation

◆ ConvertFromString< TType >()

static TType NanoByte.Common.Values.AttributeUtils.ConvertFromString< TType > ( this string  value)
static

Uses the type converter for TType (set by TypeConverterAttribute) to parse a string.

◆ ConvertToString< TType >()

static string NanoByte.Common.Values.AttributeUtils.ConvertToString< TType > ( this TType  value)
static

Uses the type converter for TType (set by TypeConverterAttribute) to generate a string.

◆ GetAttributes< TAttribute, TTarget >()

static IEnumerable<TAttribute> NanoByte.Common.Values.AttributeUtils.GetAttributes< TAttribute, TTarget > ( )
inlinestatic

Gets the first TAttribute attribute set on the TTarget type.

Returns
Falls back to object.ToString if the attribute is missing.
Type Constraints
TAttribute :Attribute 

◆ GetAttributeValue< TAttribute, TValue >()

static ? TValue NanoByte.Common.Values.AttributeUtils.GetAttributeValue< TAttribute, TValue > ( this Assembly  assembly,
[InstantHandle] Func< TAttribute, TValue?>  valueRetrieval 
)
inlinestatic

Retrieves a single value from a Custom Attribute associated with an Assembly.

Template Parameters
TAttributeThe type of Custom Attribute associated with the assembly to retrieve.
TValueThe type of the value to retrieve from the TAttribute .
Parameters
assemblyThe Assembly to retrieve the TAttribute from.
valueRetrievalA callback used to retrieve a TValue from a TAttribute .
Returns
The retrieved value or null if no TAttribute was found.
Type Constraints
TAttribute :Attribute 
TValue :class 

◆ GetEnumAttributeValue< TAttribute >()

static string NanoByte.Common.Values.AttributeUtils.GetEnumAttributeValue< TAttribute > ( this Enum  target,
Converter< TAttribute, string >  valueRetriever 
)
inlinestatic

Gets the first TAttribute attribute set on the target enum value. Then retrieves a value from the attribute using valueRetriever .

Returns
Falls back to object.ToString if the attribute is missing.
Type Constraints
TAttribute :Attribute 

The documentation for this class was generated from the following file: