uncategorized

Edmug Code Generation Presentation

Last night I presented at Edmug on Code Generation using myGeneration.  We covered off a basic Business/Domain object creation script and then added some inheritance, interfaces and code retention to it.  Most of the concepts that I wanted to discuss have already been posted on my blog here.  I’ve also added the following content for download

The extra goodies now. 

Last night I wanted to show the ease of adding a checkbox to the myGeneration UI that I had prompting me prior to the generation occurring.  Unfortunately I forgot how to write the code.  If you download the script here you will get it complete with said checkbox. 

The second goodie comes from a eureka moment that I had today.  Last night I was showing how interfaces could be worked with in the script and I mentioned that I wasn’t sure how I could write a Preserve block that would retain custom interfaces added to a class.  Well I figured it out for my C# code.  You add the Preserve block to the line immediately after the end of the class definition line (after all the classes and interfaces that the generator adds to the class).  You end up with generated code like this:

1
2
3
4
5
public class AspNetMembership : Edmug.Demo.Data.Generated.AspNetMembership
//p PRESERVE_BEGIN Interface Def p////p PRESERVE_END Interface Def p//
{
//p PRESERVE_BEGIN Interface Code p////p PRESERVE_END Interface Code p//
}

When you manually add an interface to the class your code will look like this and both the interface definition and code will be preserved:

1
2
3
4
5
6
7
8
9
10
11
public class AspNetMembership : Edmug.Demo.Data.Generated.AspNetMembership
//p PRESERVE_BEGIN Interface Def p//
,ICustomInterface
//p PRESERVE_END Interface Def p//
{
//p PRESERVE_BEGIN Interface Code p//
public void CustomMethod()
{
}
//p PRESERVE_END Interface Code p//
}

If you have any questions about the downloads leave a comment here and I will get back to you.