首页 > 其他 > 详细

EMF中复制对象属性

时间:2015-01-09 19:13:27      阅读:269      评论:0      收藏:0      [点我收藏+]

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);
            }
        }
    }    

 

EMF中复制对象属性

原文:http://www.cnblogs.com/demonrain/p/4213822.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!