Navigating the properties of a struct in ocl

Expand / Collapse
 
     

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)


User Comments

Click to subscribe to comments RSS feed...

No Member Photo
View Members Profile...,Posted By by pedro_brown added den 16 januari 2009
New Member with 0 recognition pointsNew Member with 0 recognition pointsNew Member with 0 recognition pointsNew Member with 0 recognition pointsNew Member with 0 recognition pointsNew Member with 0 recognition pointsNew Member with 0 recognition pointsNew Member with 0 recognition points


How is the struct saved to the database?<br /><br />Thanks<br />
Helpful? YesYes NoNo

Add Your Comments


Name: *
Email Address:
Web Address:
Verification Code:
*
 

Details
Last Modified:den 8 januari 2009
Last Modified By: Jonas Högström
Type: HOWTO
Article not rated yet.
Article has been viewed 844 times.
Options