using include templates

Posts   
 
    
Posts: 56
Joined: 08-Jun-2010
# Posted on: 20-Jul-2010 14:50:22   

Hello

I want to add some additional code to my entities so I'm looking at using the included templates mechanism. in particular Custom_EntityAdapterTemplate

The code I'm adding requires an extra namespace to be added as a using at the top of the class. how do I specify this?

Also I could do with having each entity implement a generic interface eg ISuperEntity<T> where T is the Entity type eg:

internal partial class UserEntity : CommonEntityBase, ISuperEntity<UserEntity>

thanks ~Brett

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 20-Jul-2010 14:55:54   

Add the additional namespace to the 'Additional Namespaces' for an entity definition in the Project properties -> Code gen. meta-data defaults'. every entity class then will have the additional namespace embedded in the class file.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 56
Joined: 08-Jun-2010
# Posted on: 20-Jul-2010 15:00:44   

Thanks!

I was editing my question when you answered. Any Idea about the interface?

~Brett

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 20-Jul-2010 15:08:54   

BrettBailey wrote:

Thanks!

I was editing my question when you answered. Any Idea about the interface?

~Brett

Well, in that dialog you also have a tab called..... Additional Interfaces! sunglasses

Frans Bouma | Lead developer LLBLGen Pro
Posts: 56
Joined: 08-Jun-2010
# Posted on: 20-Jul-2010 15:11:43   

Ah.. just spotted it in the tab next to 'Additional Namespaces' :-)

that seems to do the job nicely. one question though is there any way to specify this in the my .tasks, .preset or .templatebinding file? - I'm trying to put together a set of templates to resuse on multiple projects. As the actual implementation of the interface is taking place in an include template and is easily shareable it would be nice if I can do the same with the namespaces and interfaces instead if having to remember to go in and set it?

Thanks ~Brett

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 20-Jul-2010 21:40:44   

You could always add it to the templates themselves...?

Matt

Posts: 56
Joined: 08-Jun-2010
# Posted on: 21-Jul-2010 10:56:48   

Thanks Matt, That's not a bad idea but I was hoping to avoid editing the actual llblgen templates to make it a bit easier to integrate future changes from yourselves.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 21-Jul-2010 12:28:48   

BrettBailey wrote:

Ah.. just spotted it in the tab next to 'Additional Namespaces' :-)

that seems to do the job nicely. one question though is there any way to specify this in the my .tasks, .preset or .templatebinding file? - I'm trying to put together a set of templates to resuse on multiple projects. As the actual implementation of the interface is taking place in an include template and is easily shareable it would be nice if I can do the same with the namespaces and interfaces instead if having to remember to go in and set it? Thanks ~Brett

That's not possible at the moment. What you could do instead is generating partial classes instead. So generate a separate file, with a partial class of the entity class and in there specify your code, interface implementation and extra namespaces. This is then embedded into the template so you don't have to require the specifications for each project.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 56
Joined: 08-Jun-2010
# Posted on: 21-Jul-2010 12:57:27   

Thanks Frans

just to clarify: Instead of using an "include template" I write a template to generate a second auto generated partial entity class. This keeps my related code, interface and namespace declarations all in one place. If I have any 'project entity specific' code I can add that to a third hand-coded partial class file.

I really like that idea. I think it might be worth mentioning this in the documentation under "Adding your own code to generated classes". When the documentation talks about partial classes it is in the context of hand coding them. Auto Generating additional parts is a powerful approach which I bet would benefit a lot of your users!

Thanks for the help! ~Brett