Table of Contents

Class TypeUtilities

Namespace
Avalonia.Utilities
Assembly
Avalonia.Base.dll

Provides utilities for working with types at runtime.

public static class TypeUtilities
Inheritance
TypeUtilities
Inherited Members

Methods

AcceptsNull(Type)

Returns a value indicating whether null can be assigned to the specified type.

public static bool AcceptsNull(Type type)

Parameters

type Type

The type.

Returns

bool

True if the type accepts null values; otherwise false.

AcceptsNull<T>()

Returns a value indicating whether null can be assigned to the specified type.

public static bool AcceptsNull<T>()

Returns

bool

True if the type accepts null values; otherwise false.

Type Parameters

T

The type

CanCast<T>(object?)

Returns a value indicating whether value can be casted to the specified type. If value is null, checks if instances of that type can be null.

public static bool CanCast<T>(object? value)

Parameters

value object

The value to check if cast possible

Returns

bool

True if the cast is possible, otherwise false.

Type Parameters

T

The type to cast to

ConvertImplicitOrDefault(object?, Type)

Convert a value to a type using the implicit conversions allowed by the C# language or return the default for the type if the value could not be converted.

public static object? ConvertImplicitOrDefault(object? value, Type type)

Parameters

value object

The value to convert.

type Type

The type to convert to.

Returns

object

A value of type.

ConvertImplicit<T>(object?)

public static T ConvertImplicit<T>(object? value)

Parameters

value object

Returns

T

Type Parameters

T

ConvertOrDefault(object?, Type, CultureInfo)

Convert a value to a type by any means possible, returning the default for that type if the value could not be converted.

public static object? ConvertOrDefault(object? value, Type type, CultureInfo culture)

Parameters

value object

The value to convert.

type Type

The type to convert to.

culture CultureInfo

The culture to use.

Returns

object

A value of type.

Default(Type)

Gets the default value for the specified type.

public static object? Default(Type type)

Parameters

type Type

The type.

Returns

object

The default value.

IsNumeric(Type)

Determines if a type is numeric. Nullable numeric types are considered numeric.

public static bool IsNumeric(Type type)

Parameters

type Type

Returns

bool

True if the type is numeric; otherwise false.

Remarks

Boolean is not considered numeric.

TryConvert(Type, object?, CultureInfo?, out object?)

Try to convert a value to a type by any means possible.

public static bool TryConvert(Type to, object? value, CultureInfo? culture, out object? result)

Parameters

to Type

The type to convert to.

value object

The value to convert.

culture CultureInfo

The culture to use.

result object

If successful, contains the convert value.

Returns

bool

True if the cast was successful, otherwise false.

TryConvertImplicit(Type, object?, out object?)

Try to convert a value to a type using the implicit conversions allowed by the C# language.

public static bool TryConvertImplicit(Type to, object? value, out object? result)

Parameters

to Type

The type to convert to.

value object

The value to convert.

result object

If successful, contains the converted value.

Returns

bool

True if the convert was successful, otherwise false.