Adding custom code to a partial class

Posts   
 
    
Posts: 254
Joined: 16-Nov-2006
# Posted on: 14-Mar-2007 10:25:26   

Guys,

Currently I'm adding custom BL code to the generated code ( .NET 2.0 ) in the section

    #region Custom Entity code

    // __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode
    // __LLBLGENPRO_USER_CODE_REGION_END

However I thought as .NET 2.0 supported partial classes a better way would be for LLBLGen to generate a partial class which didn't contain any regions and allowed you to add custom code in any area of the definition.

This is the change which Visual Studio .NET went through from 2003 to 2005 i.e. when the designer code region were moved from the main class file in an "Initialize Component dont touch" type region and into another partical class called perhaps Form1.Designer.cs.

Is it possible to configure LLBLGen 2.0 in this way for .NET 2.0 classes or modify the templates accordingly. It seems strange that if you specify .NET 2.0 for code generation that this kind of structure isn't automatically generated for you and you have to add code to custom regions.

Thoughts please?

Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 14-Mar-2007 11:02:50   

Hi,

check this thread :

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=3339&HighLight=1

Indeed you have to modify the template.

Cheers,

Aurélien

Posts: 254
Joined: 16-Nov-2006
# Posted on: 14-Mar-2007 17:47:27   

This thread seems to mention you would have to modify the template, however I dont understand the point Frans raised on how this should be done exactly.

Frans quote

All you've to do is copy the entity class templates, add 'partial' to the class definition (public class <[CurrentEntityName]>Entity becomes public partial class ... ) and you're good to go!

Can you eloborate on how you do this exactly? Where do you put the template file, and would you name the file something different e.g. you have UserEntity by default so would you have a second file called UserCustomEntity.cs which is just the custom code generated by the user.

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 15-Mar-2007 01:41:30   

Are you using Adapter or Self Servicing?

Posts: 254
Joined: 16-Nov-2006
# Posted on: 15-Mar-2007 09:36:47   

Self servicing

Posts: 254
Joined: 16-Nov-2006
# Posted on: 15-Mar-2007 09:36:47   

Self servicing

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Mar-2007 10:29:02   

In general, please check the LLBLGen Pro manual: Generated code - Adding your own code to the generated classes There it discusses how to add code with Partial Classes and with include Templates.

For more details on Templates, please check the LLBLGen Pro SDK manual.

Good Luck.

Posts: 254
Joined: 16-Nov-2006
# Posted on: 15-Mar-2007 10:36:21   

Thanks I will review in due course however surely someone must have done this too

Would anyone be so kind as to post the modified templates they've created?

Perhaps we could have a section where people could post good modifications to the templates.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Mar-2007 14:14:00   

Perhaps we could have a section where people could post good modifications to the templates.

Check this out: Template Studio and Custom Templates