我想能够检查的对象是否是给定类的后代,但它似乎并不可能。
我想从端口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相同的功能的最佳方式?请注意,一个对象可能被后代几类,我测试的。
您是否尝试过Std.is()
?
if (Std.is(system, IInitializeSystem)) {
_initializeSystems.add(cast system);
}
if (Std.is(system, IExecuteSystem)) {
_executeSystems.add(cast system);
}
// etc