HiOk - so I've done OclOperations and calling static methods dynamically. How hard could it be to combine them???
So here's a sample solution (attached) that executes static methods using OCL.
StaticMethodInvoker is a transient class, with properties for the model dll and namespace. These are needed to invoke the static methods using reflection. This should be a singleton, and do not create this in code so only created using the static method StaticMethodInvoker.GetInstance(). This method also sets the values needed for reflection.
So an OclOperation is needed to create an instance of our StaticMethodInvoker (StaticMethodServiceCustomOcl.cs)
This class can then be created by the Ocl: StaticMethodInvoker.GetStaticInvoker
We now have an instance of a class using ocl which is required for the Custom Ocl Operation, and this class contains the references needed for reflection.
We can now execute our static method invoker ocloperation with ocl like this (StaticOclMethod.cs)
StaticMethodInvoker.GetStaticInvoker.ExecuteStaticMethod('ClassName', 'MethodName', 'Parameters')
(Note all string values at this time)
The return types available at this time are:
IElement, IObject, IObjectList, string, int, datetime, long, double, bool
Samples in application
StaticMethodInvoker.GetStaticInvoker.ExecuteStaticMethod('Customer', 'GetAllByName', 'Nick') - returns IObjectList of Customer instances
StaticMethodInvoker.GetStaticInvoker.ExecuteStaticMethod('Customer', 'GetCurrentDateTime', '') - returns a DateTime
EcoSpace.cs
In the EcoSpace file you need to register the OclOperations on initialize.
Also, I need to get an IEcoServiceProvider into the OclOperationBase class, this is done by having a GlobalEcoSpace class, with a static EcoSpace value. This is defined at the bottom of the EcoSpace.cs file and set during Initialize.
Help Needed
If anyone can give any pointers on the following:
1. Overloaded OclOperations so I can pass values other than strings to the same OclOperation
2. Open parameter number oclOperations, so more than one parameter can be passed to the static method
3. How to return any type, rather the IElement and simple types
Any other thoughts on how to improve the code would be much appreciated.
Hope this is of use......
Nick
PS - Credit goes to nagir for creating a transient singleton with ocl from a solution he gave me 2 years or so ago (StaticMethodServiceCustomOcl.cs)