Avec l'aide de Jonas Hogstrom et Jan Nordén J'ai écrit 2 fonctions pour évaluer OCL.

Le premier est d'évaluer dans Ecospace OCL:
EvaluateOclInEcoSpace objet public (IElement rootValue, string OCL)
(
object result = null;
IElement e = ((IOclService)
this.GetEcoService (typeof (IOclService))). EvaluateAndSubscribe (rootValue, OCL,
null, null);
if (e! = null)
result = e.AsObject;
return result;
)

Le second est d'évaluer OCL en PS:

EvaluateOclInDB objet public (IElement rootValue, string OCL)
(
object result = null;
IElement InternalElement = null;
IOclService oclService = (IOclService)
this.GetEcoService (typeof (IOclService));
IPersistenceService persistenceService = (IPersistenceService)
this.GetEcoService (typeof (IPersistenceService));
AbstractCondition cond = oclService.CreateRetrieveCondition (rootValue,
null, OCL);
InternalElement = persistenceService.GetAllWithCondition (cond, 1, 0);
if ((InternalElement! = null) & & ((InternalElement comme IObjectList). Count
== 1))
result = (InternalElement comme IObjectList) [0]. AsObject;
return result;
)

Bien sûr vous pouvez faire ces fonctions plus complexes.

Vous pouvez retourner des résultats différents types, par exemple IObjectList, changer les paramètres de GetAllWithCondition - dans cette version, il ne renvoie que le premier objet.

Average rating: