Task Based Code Generation

LLBLGen Pro uses a modular code generator. In fact, it's not a code generator per se, it's a task based engine which executes tasks and one of them can be a task to generate code. When you have defined some entities or other elements in a project, you can generate the project.

When you start the generating process, LLBLGen Pro presents you a window which will allow you to configure the generation process: the target language, the target platform, the template group to use and the presets of tasks to run for this generation cycle (which is fully configurable).

This section describes briefly the tasks and preset concepts, which are stored in .tasks and .preset files respectively.

Tasks, task groups, .tasks files and .preset files

The generator engine works by executing tasks defined in a given order. Which tasks and in which order is defined in a so called preset, stored in a .preset file and which you can create in the Presets Viewer.

Presets define a specific order of task definitions and per task the parameter values for that task. Tasks can be nested into task groups which can be nested into each other. Each task group is executed before the next one, and they are executed in the order they appear.

Tasks and task groups are stored in tasks files which have the file extension .tasks. Presets are stored in files with the file extension .preset. Both .tasks and .preset files are stored in the Tasks folder of the Target Framework used in the project, or in the additional Tasks folder specified in the Project Settings. LLBLGen Pro ships with a variety of tasks and preset files so you can get started right away. If you want to create your own, you can, they're simple XML files which use .xsd schemas defined in the Xsds folder of the LLBLGen Pro installation folder. Which tasks and the order in which they're executed are fully controllable by you.

Task performers

Each task is performed by the assembly and class specified with the task in the task definition. The generator loads the assembly specified and creates an instance of the task performer class. The task performer class has to implement a known interface, ITaskPerformer, which allows the generator to execute the task performer.

The task performer class has to derive from a supplied base class, which already implements the interface in question. This way, creating your own task performer is very easy and can be plugged into the generator process without much effort. The complete project definition is available to the task performer class so it can do whatever it wants with it.

Additionally, there's a global cache to store values which should be communicated to other task performers. For example, the CodeEmitter task performer of LLBLGen Pro is stored in the cache created once, so it doesn't have to load itself each time a new class has to be generated. Task performers can signal the generator to abort the complete generation process, or simply signal that they failed but that the total process should continue.

Task parameters

Each task can have an unlimited number of parameters with a name-value structure. These parameters are supplied to the task performer instance when the task is executed. If you look at the supplied .tasks and .preset files you get an idea what's possible with the shipped task performers. For details about these parameters, how to create your own task performer class and how to tweak the generator process in general, please see the LLBLGen Pro SDK, which is a free download for LLBLGen Pro customers.