Build a template to iterate through non-LLBLGen data

Posts   
 
    
cds avatar
cds
User
Posts: 20
Joined: 01-Feb-2006
# Posted on: 10-Oct-2006 21:23:53   

Hi

I'm wanting some help implementing my grand vision!

I'm reasonably new to template studio but have been through the tutorial and am finding my way around reasonably easily.

I have built a plug-in for the designer which allows me to design business object classes which will then use LLBLGen as the data access layer. The plug-in is working fine, and I'm persisting the designed object model to a XML file in the same folder as the project's LGP file. (In essence, I'm just piggy-backing on LLBLGen to project information for my data access).

What I'm wanting to do now is hook into the code generation process - essentially use LLBLGen to generate my business object classes - and for this, I'll need to gain access to my business object class Object Model (essentially the de-serialised version of my XML file). What I want to do is be able to write templates that I can then call for each object in my business object model (which probably won't/may not correspond directly to my data access classes).

From the experiments I've done so far, the only way I can see of doing this is to subclass the DotNetTemplateEngine class and copy (i.e. steal) the code from the Perform method to allow me to compile the templates and then access my business object model and then iterate through my business objects, calling the compiled LPT template for each one.

This sounds very convoluted, and maybe this is just because I'm trying to bend LLBLGen to fit something it's not intended for - essentially I'm trying to use it as a general purpose Code Generator (and a bloody good one, at that! simple_smile ).

At the very least, my job would be easier is I could just sub-class the DotNetTemplateEngine class and then have a custom emitType - in fact if the Perform method was refactored out so that the actual "emit" part was in a separate method, I could just override that one method and make it do what I wanted.

Am I crazy? Any thoughts on whether I'm on the right track would be much appreciated and warmly received!

Craig

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39776
Joined: 17-Aug-2003
# Posted on: 11-Oct-2006 10:06:13   

You could do this in a normal .lpt template I think. Deserialize the object model to the task cache (_executingGenerator.TaskCache, see reference manual of SDK) and then access it in all your .lpt templates instead of accessing the _executingGenerator.ProjectDefinition.

Frans Bouma | Lead developer LLBLGen Pro
cds avatar
cds
User
Posts: 20
Joined: 01-Feb-2006
# Posted on: 11-Oct-2006 22:10:23   

Thanks Frans

Yes, I did think this could be done this way, but the issue I have then is that my template needs to deal with my collection of business objects (and itself take care of the iteration through each one) instead of the template being presented with a single business object to generate the code for.

Actually since I wrote the first post, I've got it working (as I initially described) to my satisfaction. It's just it still feels a bit dirty - but the end result is worth a little roll in the mud! simple_smile

Craig

jfreeman
User
Posts: 2
Joined: 15-Mar-2007
# Posted on: 15-Mar-2007 18:49:04   

Craig,

I have been looking at CSLA and LLBLGen and I came upon your posts on both forums. Can you tell me how you integrated the 2? How difficult is it to make them work together? Thanks.

Jonathan

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 16-Mar-2007 05:34:10   

Please post this in a new thread. Thanks.