码迷,mamicode.com
首页 > 其他好文 > 详细

EMF中复制对象属性

时间:2015-01-09 19:13:56      阅读:118      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!