This article was moved to MDriven Wiki – Custom types and custom operations in OCL
We got this Question:
I have an attribute of type TestStruct defined on a class.
TestStruct is defined as follows:
The following Ocl expression gives an error “Eco.FrameworkImpl.Ocl.EBoldOCLAbort: 31:Undefined operation: CompareTo”
However, the expression
Why is this happening?
So there are a couple of things that are interesting in this:
- ECO can use any native type you define as a type of an attribute (beware you will need to explain how to persist the type if you want to store it in a database – AbstractSingleColumnAttribute, ISingleColumnAttributemapping, IDefaultReverseMapping)
- ECO will pick up on Methods of this native type and make them available in the Object constraint language – OCL – so that you can use the method in OCL and EAL.
So how come CompareToX works but CompareTo does not work?
Answer: CompareTo is common and well-known so we hijack it and map it to the “=”-operator of OCL. You need to go like this:
But while testing this I was surprised to find that my CompareTo was still not called… It turned out that we in ECO used the Equals operator, so you would need to amend your struct code with something like this: (GetHashCode override is to avoid warning)
It all seemed a bit complex in the end so new builds of ECO has been changed to call look like this:
Which in turn means that we from now and on will use IComparable, if implemented, for checking Equality on attribute types.