我不确定是否有更优雅的解决方案,但我最终做了这个长手。
在我的具体情况下,我想更改注册对象的类,但保留其他属性。这是我最终使用的方法:
private function cloneDefinition(objectDefinition:ObjectDefinition,replacementClass:Class):ObjectDefinition
{
switch (true)
{
case objectDefinition is DefaultSingletonObjectDefinition:
return new DefaultSingletonObjectDefinition(ClassInfo.forClass(replacementClass),objectDefinition.id,objectDefinition.registry);
case objectDefinition is DefaultDynamicObjectDefinition:
return new DefaultDynamicObjectDefinition(ClassInfo.forClass(replacementClass),objectDefinition.id,objectDefinition.registry);
}
throw new Error("Support for cloning object definitions of type " + getQualifiedClassName(objectDefinition) + " not yet supported");
}