RunCSharp Activity
Purpose: Executes C# code. This activity allows you to write and execute C# code directly within your workflow, providing maximum flexibility for custom logic.
Input Properties
The C# code to execute. This can be any valid C# code that returns a value or performs operations.
Type: string
Default: "" (empty string)
Required: No (but nothing happens if empty)
Note: The script has access to workflow context, variables, and can use SetOutcome() to control flow.
A list of possible outcomes that can be set by the script. Use SetOutcome(string) or SetOutcomes(params string[]) in your script to set outcomes.
Type: ICollection<string>
Note: Define the outcomes that your script might set. If not set, defaults to "Done".
Output Properties
The result value returned by the C# script, if any.
Type: object
Note: Contains the return value of the script execution. Will be null if the script doesn't return a value.
Usage Example
Scenario: Calculate a value using C# code
Configuration:
- Script:
var x = Variables.Get<int>("Input1");
var y = Variables.Get<int>("Input2");
return x * y + 10;
- PossibleOutcomes: ["Done"]
Result:
- The script executes and calculates the result
- Result output contains the calculated value (x * y + 10)
- Activity completes with "Done" outcome
Scenario: Conditional outcome based on calculation
Configuration:
- Script:
var count = Variables.Get<int>("ItemCount");
if (count > 100) {
SetOutcome("High");
} else {
SetOutcome("Low");
}
- PossibleOutcomes: ["High", "Low"]
Result:
- Script evaluates the condition
- Activity completes with either "High" or "Low" outcome
- Subsequent activities can branch based on the outcome
Important Notes
- The script has access to
Variablesto read and write workflow variables - Use
SetOutcome(string)to set a single outcome - Use
SetOutcomes(params string[])to set multiple outcomes - If no outcome is set, defaults to "Done"
- The script can return a value which will be available in the Result output
- Script execution is sandboxed and may have security restrictions
- For complex logic, consider creating custom activities instead of inline scripts
- Script errors will cause the activity to fault
Related Activities
- RunJavaScript - Execute JavaScript code instead of C#
- SetVariable - Set variables that can be used in scripts
- If - For simple conditional logic without scripting