|
Re: reflection [message #427963 is a reply to message #427962] |
Sat, 07 March 2009 11:01 |
|
You must reflectively get the list that represents your reference
feature out of your object, then use that list normally:
EObject object = ...
EStructuralFeature feature =
object.eClass().getEStructuralFeature(featureName);
EList list = (EList)object.eGet(feature);
list.add(...);
Cheers
/Eike
----
http://thegordian.blogspot.com
exquisitus schrieb:
> Hi All,
>
> How can I use reflection in emf in order to add an item into a
> collection ? I tried the piece of code below but if fails.
>
> //retrieve the feature I want to modify
> EStructuralFeature feature = getFeature(featureName);
> //retrieve the metaclass I want to instanciate
> EClass metaClass = (EClass) modal.getEClassifier(metaClassName);
> //instanciate the metaclass
> Ebject o = myFactory.create(metaClass);
> //set the feature
> if (feature.getUpperBound == 1)
> element.eSet(feature, o);
> else
> ((EList<EObject>)feature).add(o);
>
> I can't see what's wrong. Any Idea ?
> thx for help.
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
|
Powered by
FUDForum. Page generated in 0.03195 seconds