Source Generators
ALPHA - FLOW ACTION GENERATOR ONLY
Switchboard is currently in preview (v0.1.0-preview.62). Currently, only the FlowActionGenerator is implemented. Other generators listed in older documentation (DynamoDB, Lambda) do not yet exist. See the roadmap for planned features.
Switchboard uses C# source generators to automatically create flow implementations from your attribute-decorated classes. This eliminates boilerplate code and ensures consistency across your contact center infrastructure.
What Are Source Generators?
Source generators are compile-time code generators that analyze your code and produce additional C# source files. They run as part of the compiler pipeline, so generated code is available immediately with full IntelliSense support.
Your Code (Attributes)
↓
Roslyn Compiler
↓
Source Generator Analysis
↓
Generated Code (automatic)
↓
Final CompilationCurrent: FlowActionGenerator
What It Does
The FlowActionGenerator analyzes [FlowAction]-decorated classes and generates extension methods on IFlowBuilder:
Input: Your Flow Action
using Switchboard.SourceGenerators.Attributes;
[FlowAction("PlayMessage")]
public class PlayMessageAction : FlowAction
{
[Parameter]
public string Text { get; set; }
[Parameter]
public string Voice { get; set; } = "Joanna";
}Output: Generated Extension Method
// Generated by FlowActionGenerator
public static IFlowBuilder PlayMessage(
this IFlowBuilder builder,
string text,
string voice = "Joanna")
{
var action = new PlayMessageAction
{
Identifier = $"play-message-{Guid.NewGuid().ToString()[..8]}",
Text = text,
Voice = voice
};
return builder.AddFlowAction(action);
}Usage:
var flow = new FlowBuilder()
.SetName("WelcomeFlow")
.SetType(FlowType.ContactFlow)
.PlayMessage("Welcome to our support center", "Matthew")
.TransferToQueue("GeneralSupport")
.Build();Available Attributes
[FlowAction]
Marks a class for extension method generation.
[FlowAction("PlayMessage")]
public class PlayMessageAction : FlowAction { }[Parameter]
Marks a property as a method parameter. Only marked properties appear in the generated method signature.
[FlowAction("PlayMessage")]
public class PlayMessageAction : FlowAction
{
[Parameter]
public string Text { get; set; } // In signature
public string InternalId { get; set; } // Not in signature
}[Transition]
Marks a property for transition routing information.
[FlowAction("Router")]
public class RouterAction : FlowAction
{
[Transition]
public Dictionary<string, string> Routes { get; set; }
}Best Practices
- Inherit from FlowAction — All action classes must extend
FlowAction - Use
[Parameter]selectively — Only mark properties you want in the generated method - Provide defaults — Use default values for optional parameters
- Use clear names — Name your action classes descriptively
Future: More Generators (Post-v1.0)
Planned generators for future releases:
- FlowDefinitionGenerator - For
[ContactFlow]attribute-based flows - DynamoDbSchemaGenerator - For
[DynamoDbTable]configuration models - LambdaHandlerGenerator - For
[LambdaHandler]interface-based handlers
For now, use the fluent API for all flow and resource definitions.
See Also
- Attributes Guide - Current attribute support
- Fluent API - Primary way to build flows
- Examples - Working code samples