C#
In this section, we cover some of the built-in variables and functions available to the C# expression syntax.
When creating workflows, you'll often need to write dynamic expressions. This page provides an overview of enabling C# expressions and what objects you can use.
Installing the C# Feature
The C# Expressions feature is provided by the following package:
You can enable the feature as follows:
Configuration
The UseCSharp
extension provides an overload that accepts a delegate that lets you configure CSharpOptions
. These options let you configure what assemblies and namespaces to make available to C# expressions, and provides a way to register additional reusable global methods.
For example:
Elsa uses Roslyn to implement the C# expression evaluator.
Out of the box, the following namespaces are available:
System
System.Collections.Generic
System.Linq
System.Text.Json
System.Text.Json.Serialization
System.Text.Nodes
Globals
The following members are available as globals to all C# expressions:
WorkflowInstanceId
Type: String.
The WorkflowInstanceId
property returns the workflow instance ID of the currently executing workflow.
Example usage:
CorrelationId
Type: String.
The CorrelationId property gets or sets the correlation ID of the currently executing workflow.
Example usage:
Variable
The Variable object provides access to the following methods and properties related to accessing workflow variables:
In addition, the Variable
object provides strongly-typed access to all workflow variables. For example, if your workflow defines a variable called OrderId
of type Guid
, the following property will be available on the Variable
object:
Output
The Output
object provides access to the following methods and properties related to accessing activity output:
Input
The Input
object provides access to the following methods related to accessing workflow input:
In addition, the Input
object provides strongly-typed access to all workflow-defined inputs. For example, if your workflow defines an input called OrderNumber
of type string
, the following property will be available on the Input
object:
Adding Assemblies and Namespaces
You can make available additional assemblies and namespaces to C# expressions by configuring the C# Expression Feature from your application's startup code. For example:
Last updated