Skip to main content



      Home
Home » Modeling » EMF » Reading attribute value from EObject programmatically
Reading attribute value from EObject programmatically [message #966908] Thu, 01 November 2012 06:31 Go to next message
Eclipse UserFriend
Hi,

I have an EObject of an EClass with an integer attribute named 'a'. Is is possible to
read the value for this attribute from the EObject, intuitively like this (pseudo code):

EObject o ... ;
EAttribute a = o.eClass.getAttribute( "a" );
int aValue = o.getValue( a );

I've searched the API, but couldn't find how to do this.
Re: Reading attribute value from EObject programmatically [message #966925 is a reply to message #966908] Thu, 01 November 2012 06:44 Go to previous messageGo to next message
Eclipse UserFriend
Peter,

You can use o.eGet(a).

On 01/11/2012 11:31 AM, Peter Johnsen wrote:
> Hi,
>
> I have an EObject of an EClass with an integer attribute named 'a'. Is
> is possible to
> read the value for this attribute from the EObject, intuitively like
> this (pseudo code):
>
> EObject o ... ;
> EAttribute a = o.eClass.getAttribute( "a" );
> int aValue = o.getValue( a );
>
> I've searched the API, but couldn't find how to do this.
Re: Reading attribute value from EObject programmatically [message #966939 is a reply to message #966925] Thu, 01 November 2012 07:00 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for your prompt reply!

OK, but if I don't have the EAttribute object? That is, I only have the name of the attribute? Are there any EMF-ways to do this, or would I have to use reflection?
Re: Reading attribute value from EObject programmatically [message #966956 is a reply to message #966939] Thu, 01 November 2012 07:13 Go to previous messageGo to next message
Eclipse UserFriend
Peter,

You need the EStructuralFeature, but as you showed in your own code, you
already know how to get that from the EObject's eClass().


On 01/11/2012 12:00 PM, Peter Johnsen wrote:
> Thanks for your prompt reply!
>
> OK, but if I don't have the EAttribute object? That is, I only have
> the name of the attribute? Are there any EMF-ways to do this, or would
> I have to use reflection?
Re: Reading attribute value from EObject programmatically [message #966961 is a reply to message #966956] Thu, 01 November 2012 07:23 Go to previous message
Eclipse UserFriend
Ah, exactly! Thanks!
Previous Topic:EMF Notification: how to not get our own modifications?
Next Topic:EMF resource how to flush to disk
Goto Forum:
  


Current Time: Wed Jul 23 01:48:09 EDT 2025

Powered by FUDForum. Page generated in 0.06910 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top