← Back to API Reference

Delegate Types

RoslynRules takes exactly one input parameter per expression or action. That single parameter is invoked through a fast, strongly-typed delegate. To pass several inputs — or to return several values — wrap them in a struct or class.


Supported Signatures

Type Delegate Example
Expression Func<TParam, bool> Func<Customer, bool>
Expression (composite return) Func<TParam, TReturn> Func<Customer, ValidationResult>
Action Action<TParam> Action<Customer>
Async Expression Func<TParam, Task<bool>> Func<Customer, Task<bool>>
Async Action Func<TParam, Task> Func<Customer, Task>

To combine multiple inputs, wrap them in one type and reference its members in the expression:

public record Order(Customer Customer, decimal Amount);

// Expression over the single wrapper parameter
"order.Customer.IsActive && order.Amount > 0"

Auto-Detection

RoslynRules automatically detects await in expressions and compiles to the appropriate async delegate.

// Sync — compiled as Func<Customer, bool>
"customer.Age >= 18"

// Async — compiled as Func<Customer, Task<bool>>
"await GetPriceAsync(customer.ProductId) > 100"

Multi-Value Return

Return composite data by wrapping in a record or class.

public record ValidationResult(bool IsValid, string[] Errors);

// Expression returns ValidationResult
"new ValidationResult(customer.Age >= 18, customer.Age < 18 ? new[] { \"Too young\" } : Array.Empty<string>())"


Back to top

MIT License. Built with Roslyn + Typed Delegates.