}
protected <T> T cast(Object object, Class<T> type) {
NativeObject base = (NativeObject) object;
T instance = I.make(type);
Model model = Model.load(type);
for (Property property : model.properties) {
Object value = base.get(property.name);
if (value == null || value instanceof Undefined) {
// do nothing
} else if (property.isAttribute()) {
model.set(instance, property, value);
} else {
model.set(instance, property, cast(value, property.model.type));
}
}
return instance;
}