Class TypeExtensions
A static class providing Type extensions
Namespace: Artemis.Core
Assembly: Artemis.Core.dll
Syntax
public static class TypeExtensions
Methods
GetDefault(Type)
Returns the default value of the given type
Declaration
public static object? GetDefault(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type |
Returns
Type | Description |
---|---|
object |
GetDisplayName(Type, bool)
Determines a display name for the given type
Declaration
public static string GetDisplayName(this Type type, bool humanize = false)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type to determine the name for |
bool | humanize | Whether or not to humanize the result, defaults to false |
Returns
Type | Description |
---|---|
string |
GetGenericEnumerableType(Type)
Determines the type of the provided generic enumerable type
Declaration
public static Type? GetGenericEnumerableType(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type |
Returns
Type | Description |
---|---|
Type |
IsCastableFrom(Type, Type)
Determines whether an instance of a specified type can be casted to a variable of the current type
Declaration
public static bool IsCastableFrom(this Type to, Type from)
Parameters
Type | Name | Description |
---|---|---|
Type | to | |
Type | from |
Returns
Type | Description |
---|---|
bool |
IsGenericEnumerable(Type)
Determines whether the given type is a generic enumerable
Declaration
public static bool IsGenericEnumerable(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type |
Returns
Type | Description |
---|---|
bool |
IsGenericType(Type?, Type)
Determines whether the provided type is of a specified generic type
Declaration
public static bool IsGenericType(this Type? type, Type genericType)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type to check |
Type | genericType | The generic type to match |
Returns
Type | Description |
---|---|
bool | True if the |
IsOfGenericType(Type, Type)
Determines if the typeToCheck
is of a certain genericType
.
Declaration
public static bool IsOfGenericType(this Type typeToCheck, Type genericType)
Parameters
Type | Name | Description |
---|---|---|
Type | typeToCheck | The type to check. |
Type | genericType | The generic type it should be or implement |
Returns
Type | Description |
---|---|
bool |
IsStruct(Type)
Determines whether the provided type is a struct
Declaration
public static bool IsStruct(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type to check |
Returns
Type | Description |
---|---|
bool |
ScoreCastability(Type, Type?)
Scores how well the two types can be casted from one to another, 5 being a perfect match and 0 being not castable at all
Declaration
public static int ScoreCastability(this Type to, Type? from)
Parameters
Type | Name | Description |
---|---|---|
Type | to | |
Type | from |
Returns
Type | Description |
---|---|
int |
TypeIsNumber(Type)
Determines whether the provided type is any kind of numeric type
Declaration
public static bool TypeIsNumber(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type to check |
Returns
Type | Description |
---|---|
bool |