Thread overview | |||||
---|---|---|---|---|---|
|
July 22, 2019 Any easy way to check if an object have inherited an interface? | ||||
---|---|---|---|---|
| ||||
It seems that I've to write my own function that searches in the given object's classinfo.interfaces since I couldn't find anything related in Phobos. |
July 23, 2019 Re: Any easy way to check if an object have inherited an interface? | ||||
---|---|---|---|---|
| ||||
Posted in reply to solidstate1991 | On 23/07/2019 9:34 AM, solidstate1991 wrote:
> It seems that I've to write my own function that searches in the given object's classinfo.interfaces since I couldn't find anything related in Phobos.
if (Foo foo = cast(Bar)bar) {
}
|
July 23, 2019 Re: Any easy way to check if an object have inherited an interface? | ||||
---|---|---|---|---|
| ||||
Posted in reply to solidstate1991 | On Monday, 22 July 2019 at 21:34:18 UTC, solidstate1991 wrote: > It seems that I've to write my own function that searches in the given object's classinfo.interfaces since I couldn't find anything related in Phobos. Do you mean...? interface I {} class C : I {} void main() { C c1; writeln(is(typeof(c1) : I)); } No need for Phobos, core language: https://dlang.org/spec/expression.html#IsExpression https://dlang.org/spec/declaration.html#Typeof |
Copyright © 1999-2021 by the D Language Foundation