1、简单的场景就是复制一个EObject,可以用工具类中的方法EcoreUtil.copy()。
2、场景:自己的TO类继承了EMF创建出的类,需要复制父类中的所有属性。
/**
* 将父类所有的属性COPY到子类中。 类定义中child一定要extends father;
* @param father
* @param child
*/
public static void fatherToChild(EObject father, EObject child) {
for (Field field : father.getClass().getDeclaredFields()) {
EStructuralFeature feature = father.eClass().getEStructuralFeature(field.getName());
if(feature!=null) {
Object value = father.eGet(feature);
child.eSet(feature, value);
}
}
}