如何检查一个对象是否是 Haxe 中给定 class 的后代?

How to check whether an object is a descendant of a given class in Haxe?

我希望能够检查一个对象是否是给定对象 class 的后代,但这似乎不可能。

我想从 C# 移植以下代码:

public virtual Systems Add(ISystem system) {
    var initializeSystem = system as IInitializeSystem;
    if(initializeSystem != null) {
        _initializeSystems.Add(initializeSystem);
    }

    var executeSystem = system as IExecuteSystem;
    if(executeSystem != null) {
        _executeSystems.Add(executeSystem);
    }

    var cleanupSystem = system as ICleanupSystem;
    if(cleanupSystem != null) {
        _cleanupSystems.Add(cleanupSystem);
    }

    var tearDownSystem = system as ITearDownSystem;
    if(tearDownSystem != null) {
        _tearDownSystems.Add(tearDownSystem);
    }

    return this;
}

在 Haxe 中实现相同功能的最佳方法是什么? 请注意,一个对象可能是我正在测试的几个 classes 的后代。

你试过了吗Std.is()

if (Std.is(system, IInitializeSystem)) {
    _initializeSystems.add(cast system);
}

if (Std.is(system, IExecuteSystem)) {
    _executeSystems.add(cast system);
}

// etc