The CodeGen API


As an alternative to using the command-line interface a developer could integrate CodeGen more tightly into their development environment by writing custom tools or utilities to generate code, using the core CodeGen environment.

To make this possible CodeGen provides a .NET API that developers can code directly against in order to generate code. The main classes in the CodeGen API are:




CodeGen API Example

This is a very simple example of using the CodeGen API. This code segment is essentially the same as using the command line:

codegen -s CUSTOMER -t DataClass -r -v

Here's the sample code:

;;Create a new task set
data taskset = new CodeGenTaskSet()
taskset.LoggingLevel = LoggingLevel.Verbose

;;Create a task and define what it shold do
data task = new CodeGenTask()
task.ReplaceFiles = true

;;Add the task to the task set

;;Create a code generator and tell it about the task set
data generator = new CodeGenerator(taskset)

;;Generate the code

;;Did it work?
if (taskset.Complete) then
          ;;Good to go
          ;;Something failed!

You won't see anything happening when you execute this code because the CodeGen API doesn't implement any UI. But if you wanted to see the messages that are generated as the task set it processed you could register an event handler method against either taskset.Messages.CollectionChanged or task.Messages.CollectionChanged and monitor / report on the messages as they are generated. For example if you were in a console application you could log messages to standard out like this:

lambda messageFromTaskSet(sender, e)
          if (e.Action==NotifyCollectionChangedAction.Add)
                    data message, String
                    foreach message in e.NewItems
                              if (message!=^null)


;;Listen for messages from the taskset as it processes
taskset.Messages.CollectionChanged += messageFromTaskSet




Copyright © 2018  Synergex International, Inc.