Skip to content

Type Extensions

Andrzej Kebab edited this page Jan 21, 2024 · 3 revisions

UtilityLibrary.Core

This utility library provides extension methods for the Type class to simplify common operations related to types.

Default

DefaultValue

Gets the default value of the specified type.

using UtilityLibrary.Core;

Type myType = typeof(int);
object defaultValue = myType.DefaultValue();

Parameters

  • type (Type): The type to get the default value for.

Returns

  • object: The default value for the specified type. For value types, this is usually the equivalent of 'new T()', and for reference types, this is null.

IsNullableType

Determines whether the specified type is a nullable type.

using UtilityLibrary.Core;

Type myType = typeof(int);
bool isNullable = myType.IsNullableType();

Parameters

  • type (Type): The type to check.

Returns

  • bool: True if the specified type is a nullable type; otherwise, False.

Numeric

IsNumericType

Checks if the specified type is a numeric type.

using UtilityLibrary.Core;

Type myType = typeof(int);
bool isNumeric = myType.IsNumericType();

Parameters

  • type (Type): The type to check.

Returns

  • bool: True if the type is numeric; otherwise, False.

Clone this wiki locally