elementFilter issue in Code Generation

Posts   
 
    
tbeyhan
User
Posts: 23
Joined: 23-May-2006
# Posted on: 14-Feb-2011 11:11:01   

Hi, I want to run some of my templates based on a custom property set on entities. For this purpose i'm using element filter. But i couldn't manage to check the specific property exists or not. using OutputSettingValues.CustomProperties.Keys.Count > 0 works, but i can't test key with Contains method

Any ideas, cheers

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 14-Feb-2011 15:50:08   

Which version of LLBLGen Pro are you using?

tbeyhan
User
Posts: 23
Joined: 23-May-2006
# Posted on: 14-Feb-2011 19:47:08   

Hi Walaa, I'm using 3.1

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 14-Feb-2011 20:28:53   

Please give more info, i.e. what you have tried in code which failed.

Frans Bouma | Lead developer LLBLGen Pro
tbeyhan
User
Posts: 23
Joined: 23-May-2006
# Posted on: 14-Feb-2011 22:01:13   

Defined custom property for two entities.when i run my template for allEntities and use an element filter OutputSettingValues.CustomProperties.Keys.Count > 0 i get two files as expected. But i can't get the same result when i use OutputSettingValues.CustomProperties.Keys.Contains("keyname") as elementFilter

Sure i'm doing something stupid but couldn't figure it out

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Feb-2011 01:18:13   

Reproduced.

Steps: - Click F7 and go to "Task queue to execute" Sub tab - For an specific CodeEmmiter task, put this on elementFilter: _OutputSettingValues.CustomProperties.Keys.Contains("keyname") _ or OutputSettingValues.CustomProperties.ContainsKey("keyname") - Result: the task is executed for all the input entities, instead of just the ones that pass the criteria.

This works if the elementFilter is OutputSettingValues.CustomProperties.Keys

We will look into it.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 15-Feb-2011 09:30:18   

The lambda defined in elementFilter is evaluated with 'DynamicQuery' which is a reflection based simple evaluator for lambdas. In short, it can't deal with things like this, it can only deal with an object and a method called onto it e.g. Count(), but not member access of a property and then call a method on it.

I know it's a limitation, but it's what is supported. A workaround is to use a frameworksettings file and define a setting and use that setting's value in a perform rule.

Frans Bouma | Lead developer LLBLGen Pro
raist
User
Posts: 114
Joined: 19-Apr-2010
# Posted on: 29-Apr-2013 20:27:03   

Horriblecry workaround for .lpt templates: 1. Do not use task parameter elementFilter. Generate for all the elements 2. At the beginning of the template check the required condition. If false -> return (generates empty file) 3. Add a last clean template to remove all the empty files checking the condition again and using executingGenerator.DestinationRootFolder

As crappy as it is, for me it is more simple (and maintainable) than generate a custom perform method as in http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=17154&HighLight=1

AtA2k7
User
Posts: 3
Joined: 28-Jul-2016
# Posted on: 09-Dec-2016 10:12:58   

How do you achive step 3 (cleanup)?

where can I find out what can be used in emitType and elementFilter parameters? cant seem to find this in the docs.

thx

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 09-Dec-2016 10:28:16   
Frans Bouma | Lead developer LLBLGen Pro