Reply to Qian,
Frits van Bommel wrote:
Qian Xu wrote:
Hi All,
can D check, whether a class A an Interface B supports?
like:
if (supports(class_A, intf_B))
if (is(class_A : intf_B))
tests if 'class_A' is implicitly convertible to 'intf_B'. If the
first
is a class and the second an interface, that's equivalent to the
class
implementing the interface.
Thanks. Could you tell me, how to make a function for this? I do not
know how to pass an Interface as parameter.
like
bool supports(T)(T obj, interface_type t)
{
return (is(obj : t));
}
Given
interface I {}
class C1 {}
class C2 : C1, I {}
class C3 : C1 {}
if you want to check if an instance of C1 is a derived class that implements
I use this
null !is cast(I)c1
if you want it in a function
bool IsA(TI, TC)(TC c)
{
return null !is cast(TI)c;
}