If StringValueEquals ... ...

Posts   
 
    
ChBaeumer
User
Posts: 175
Joined: 23-Oct-2003
# Posted on: 30-Mar-2005 18:00:52   

Hi,

I'm currently writing my own templates.

I want to do following:

Some entities have to implement a specific interface. Since the implementation of this interface is common to this entities I thought I could write a template which injects this code to these entities. Other entities of the project (more or less the (m,n) tables) do not need this interfaces.

Ok, I defined custom properties like (Name, Value): (Interface, <Name of interface>)

In the template I iterate over the properties. That's ok so far. But if I do following the output looks not OK:


<[Foreach CustomProperty Entity]><[If StringValueEquals CustomPropertyName "Interface"]>, <[CustomPropertyValue]><[EndIf]><[NextFor]>

Produces following garbage:


EntityStringValueEqualsCustomPropertyName "Interface"]>, IAssociation

I guess the CustomPropertyName is not allowed in the grammar at this place, but if would be nice to have. Then it would be possible to tag the entities with properties and write templates which act on these properties.

Christoph

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 30-Mar-2005 18:17:44   

You can't use 'CustomPropertyName' in that if statement so it throws an error.

Do you have more things you'd like to add to that if statement, so I can add them all at once? simple_smile

Frans Bouma | Lead developer LLBLGen Pro
ChBaeumer
User
Posts: 175
Joined: 23-Oct-2003
# Posted on: 30-Mar-2005 18:54:44   

Nothing I need right now since I just started to explore the possibilities of the template generator wink

Things popping in my mind:

  • case switch
  • else switch

and a kind of grammar (ebnf) would be usefull (at least for me) to see what is possible.

smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 31-Mar-2005 12:07:47   

ChBaeumer wrote:

Nothing I need right now since I just started to explore the possibilities of the template generator wink

Things popping in my mind:

  • case switch
  • else switch

I think you'd better look at .lpt templates then, TDL is a bit limited to produce custom code, as the object model in the project isn't exposed through statements. .lpt templates can be written in C# or VB.NET, and you can access the complete object model in a project.

and a kind of grammar (ebnf) would be usefull (at least for me) to see what is possible. smile

I didn't write an ebnf grammar for TDL because it's a set of statements and don't expose rules like this statement has a special expression block and can't be used inside another statement. The parser is also not LR(n) but LL(1). This is done to easily adjust the language when required without having to worry about shift/reduce conflicts in the LR parser. The parser used for this forum (my LR(n) parser generator combi wink ) for example is very inflexible because changes to the language require severe maintenance and often cause shift/reduce conflicts somewhere... which aren't necessary as TDL is a low level language to write code generation statements with the least amount of statements. The one requirement TDL had to meet was that it was absolutely fail proof and no debugging was required to fix template statements.

Frans Bouma | Lead developer LLBLGen Pro
Mountain
User
Posts: 21
Joined: 01-Apr-2005
# Posted on: 05-Apr-2005 15:37:10   

ChBaeumer wrote:

I want to do following: Some entities have to implement a specific interface. Since the implementation of this interface is common to this entities I thought I could write a template which injects this code to these entities. Other entities of the project (more or less the (m,n) tables) do not need this interfaces.

I have a similar need. I want certain entities to implement certain interfaces. * If the database table has a column called "Name", I want the entity to implement the interface called "INamedEntity". * If the table has a column called "SequenceID", I want the entity to implement "ISequencedEntity". * If the table has a column called "ID", I want the entity to implement "IUniqueEntity". Those are the only 3 situations I need to handle.

I have not yet edited any template or even opened template studio. What is the quickest way to accomplish what I need?

Would it be possible for you to post the changes I need to make to the C# entityAdapter.template file? I would love to be able to just copy a new version of entityAdapter.template into a folder and get back to work. I hope to be able to learn all about template editing at a later time. Thanks!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 06-Apr-2005 11:16:47   

That's not possible with TDL as in: TDL doesn't have these check commands.

Well, it is possible, but it's not that fast:

You could loop over the entityfields and check the SourceColumnName in an enclosed If statement. The header of the entity class in the 1.0.2004.1 version of the entityAdapter.template will then become:


public class <[CurrentEntityName]>Entity : EntityBase2, ISerializable<[Foreach EntityField]><[If StringValueEquals SourceColumnName "Name"]>, INamedEntity<[EndIf]><[If StringValueEquals SourceColumnName "SequenceID"]>, ISequencedEntity<[EndIf]><[If StringValueEquals SourceColumnName "ID"]>, IUniqueEntity<[EndIf]><[NextForeach]>

For 1.0.2004.2, you've to alter the new template also of course. If you want to test on Entity Field names instead of table field names, use EntityFieldName instead of SourceColumnName simple_smile

Frans Bouma | Lead developer LLBLGen Pro