Cadenza : Cadenza Namespace

TypeCoda Class

Extension methods for Type.

public static class TypeCoda

Remarks

Requirements

Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0

Members

See Also: Inherited members from object.

Public Methods

static
IsAssignableTo (this Type, Type) : bool
Determines whether an instance of self can be stored in a reference of a type type.
static
IsNullable (this Type) : bool
Gets a value indicating whether the type is a nullable type.

Member Details

IsAssignableTo Method

Determines whether an instance of self can be stored in a reference of a type type.

public static bool IsAssignableTo (this Type self, Type type)

See Also

Type.IsAssignableFrom(Type)

Parameters

self
A Type which is used to check that instances of type self can be stored into references of type type.
type
A Type which is the type of the reference to store an instance of type self.

Returns

true if an instance of type self can be stored into a reference of type type; otherwise, false.

Exceptions

Type Reason
ArgumentNullException self is null.

Remarks

This is equivalent to type.IsAssignableFrom(self).

C# Example
// Can string be implicitly converted to object?  Yes.
Assert.IsTrue (typeof(string).IsAssignableTo (typeof (object)));
// Can object be implicitly converted to string?  No.
Assert.IsFalse (typeof(object).IsAssignableTo (typeof (string)));

Requirements

Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0

IsNullable Method

Gets a value indicating whether the type is a nullable type.

public static bool IsNullable (this Type self)

Parameters

self
A Type containing the type to check.

Returns

true if self is a Nullable<T> type; otherwise, false.

Exceptions

Type Reason
ArgumentNullException self is null.

Remarks

self is considered to a nullable type if:

  • self is not typeof(Nullable<>).
  • self.GetGenericTypeDefinition() is typeof(Nullable<>).
C# Example
Assert.IsTrue (typeof (int?).IsNullable ());
Assert.IsFalse (typeof (int).IsNullable ());
Assert.IsFalse (typeof (string).IsNullable ());
Assert.IsFalse (typeof (Nullable<>).IsNullable ());

Requirements

Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0