Navigating the properties of a struct in ocl




If your model contains structs that you want to be able to navigate in OCL, here is how to install custom OCL operations to make it work:

First of all, define the struct:

    public struct Coord
    {
        public int x;
        public int y;
        public int z;
        public override string ToString()
        {
            return string.Format("{0}:{1}:{2}", x, y, z);
        }
    }

Then add a helper class with a static method for each of the properties:

    public struct Coord
    {
        ...
        public class CoordOclHelper
        {
            public static int x(Coord coord) { return coord.x; }
            public static int y(Coord coord) { return coord.y; }
            public static int z(Coord coord) { return coord.z; }
        }
    }

Finally, install the helper class as an OCL operation in your EcoSpace:


    [Eco.Ocl.Support.EcoOclOperation(typeof(Coord.CoordOclHelper), true)]
    public partial class EcoProject42EcoSpace: Eco.Handles.DefaultEcoSpace
    {
      ...    
    }


This will make the parts available in OCL in runtime, but not in designtime. You can now write OCL expressions like:

      aShape.Points->select(p|p.Coordinate.x > 100)