New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
making a Many Structural Feature #107
Comments
Hi @Z-Rajaei , Sorry for the late answer, I read your email but no strong internet connection nor my laptop. Indeed, playing with Considering a small metamodel and model as this one: from pyecore.ecore import *
@EMetaclass
class B(object):
...
@EMetaclass
class A(object):
single = EReference(eType=B, upper=1)
many = EReference(eType=B, upper=-1)
a = A()
a.single = B()
a.many.update([B(), B()]) The first solution would be: for ref in a.eClass.eAllReferences():
values = a.eGet(ref)
if values is None:
continue
values = values if ref.many else [values]
for x in values:
print(x) This solution iterates on each relationships from the metaclass, discard the one sending The second solution relies on monkey patching: from pyecore.valuecontainer import EValue
EValue.__iter__ = lambda self: iter([self._value])
for ref in a.eClass.eAllReferences():
for x in a.__dict__.get(ref.name, []):
print(x) In PyEcore, That should do the trick :) |
Hello,
I want to iterate on the elements that have references with my first element in this way:
for ref in model.eClass.eAllReferences(): if model.eGet(ref)!=None: for element in model.eGet(ref): <some operations>
But when ref is a single value, I can not iterate on it.
I have used if ref.many ==False to check if it is single or many value, but I don't know how to do in both cases that it is single or many!
I can not use a function because I have many variable to be passed!
Do you have any solution for it? Is it possible create a EOrderedSet if it is a single value after if ref.many ==False checking?
Thank you.
The text was updated successfully, but these errors were encountered: