Searching info for object casting with checking class type at runtime.

Like this:

class A
{
    //
}

class B
{
    int bVar;
}


unittest
{
    A a = new A();

    A x = cast( A )a;     // ok
    A x = cast( B )a;     // ok, but unsafe
    A x = safeCast( B )a; // throw exception
    A x = safeCast( A )a; // ok
}


Searching some like next:

T safeCast( CLS )( CLS o )
{
  ... // checking type of o
  ... // may be check ClassInfo...
  return T;
}

Has function like a safeCast() ?
Or other solution ? ...

  • Safe cast Виталий Фадеев via Digitalmars-d-learn

Reply via email to