unwrap

Downcast an object to component of T type.

This family of functions are aware of Wrapper!T and Castable!T interfaces, and therefore will use them in downcasting process to T component. In case if T is of class or interface type, the object is attempted to be downcast to T type first if it fails, it will continue to cast to Wrapper!T and then Castable!T to find whether component is downcastable to T type. If so, component of T type is returned, otherwise an exception is thrown. For non referenced types, direct downcast is ignored and only casting to Wrapper!T and Castable!T is attempted. In case if passed component is an object implementing Wrapper!T or Castable!T, contents of those wrappers is returned. For a component that does not implement those types, component itself will be returned.

  1. T unwrap(inout(Object) component)
    @safe @trusted
    T
    unwrap
    (
    T
    )
    (
    inout(Object) component
    )
    if (
    is(T == class) ||
    is(T == interface)
    )
  2. T unwrap(inout(Object) component)
  3. Z unwrap(T castable)
  4. Z unwrap(T wrapper)
  5. T unwrap(T wrapped)

Parameters

T

the expected type of resolved component.

component inout(Object)

component to be downcasted.

Return Value

Type: T

T referenced object

Throws

InvalidCastException when resolved component is not of expected type.

Meta