Generating C# Code#
To generate C# code, call the code generator with the command line flag -l csharp.
All states are generated into one source file, and the file name is determined by the -o switch.
The generated code does not use a classic state pattern with hand-written classes. Since machine code is fully generated, class/file count is reduced to a minimum.

Microwave Oven Example in C##
The microwave oven example from the code generator examples folder demonstrates the C# backend. It can be compiled with Microsoft Visual Studio on Windows.

A simple hardware abstraction layer provides helper functions such as timers. For example, state machine action code calls hal.ovenOff().
You can either:
- generate one state class per state, or
- inline entry/do/exit actions directly into generated machine code.
In this example, actions are inlined. Generation behavior is controlled by configuration:
Namespace=OvenMachineNS
BaseClassMachine=OvenBase
BaseClassStates=StateBase
SeparateStateClasses=NOGenerate code with:
java -Djava.ext.dirs=../bin/ -jar "../bin/codegen.jar" -p CADIFRA -l csharp -o Oven oven.cddGenerated C# code snippet:
namespace OvenMachineNS
{
public class Oven : OvenBase
{
public enum States : int{
Super,
Completed,
CookingPause,
Idle,
Cooking,
__UNKNOWN_STATE__
}
public enum Events : int {
evDoorOpen,
evDec,
evTimeout,
evDoorClosed,
evInc,
evPwrLow,
evPwrHigh,
OVEN_NO_MSG
}
// ...
public int ProcessEvent(Events msg){
int evConsumed = 0;
if(m_initialized==false) return 0;
// ...
return evConsumed;
}
}
}Finally, start the generated executable and test the microwave behavior: increment cooking time, then start cooking by closing the door.

Sinelabore codegen provides more than code generation. Before generation, extensive checks validate your diagram (for example each transition has an event, state names are unique, etc.). You can also enable trace code, simulate state machines, generate test cases, and more.
To try the example yourself, download the code generator demo and open the oven sample from the examples folder.