Skip to main content
net10.0.NETFramework4.6.2net8.0.NETStandard2.1

Cel.NET is an implementation of the Common Expression Language (CEL) for .NET

Published
Jul 2, 2026
4mo ago
Total Downloads
136.3K
136,310

Install

dotnet add package Cel.NET --version 1.1.0
ProductVersions
.NET
net10.0net8.0
.NET Standard
netstandard2.1
Other
.NETFramework4.6.2

README

Cel.NET - Common Expression Language for .NET

Build Status NuGet Package

This is a C# port of the Common Expression Language (CEL), based on CEL-Java.

The CEL specification can be found here.

Getting started

A very simple start:

using Cel.Checker;
using Cel.Tools;

public class MyClass
{
    public void MyScriptUsage()
    {
        // Build the script factory
        ScriptHost scriptHost = ScriptHost.NewBuilder().Build();

        // create the script, will be parsed and checked
        Script script = scriptHost.BuildScript("x + ' ' + y")
            .WithDeclarations(
                // Variable declarations - we need `x` and `y` in this example
                Decls.NewVar("x", Decls.String),
                Decls.NewVar("y", Decls.String))
            .Build();

        IDictionary<string, object> arguments = new Dictionary<string, object>();
        arguments.Add("x", "hello");
        arguments.Add("y", "world");

        string result = script.Execute<string>(arguments);

        Console.WriteLine(result); // Prints "hello world"
    }
}

Protobuf and Json.NET and plain C# objects

Protobuf (via Google.Protobuf) objects and schema is supported out of the box.

It is also possible to use plain C# and Json.NET objects as arguments by using the Cel.Common.Types.Json.JsonRegistry.

Code sample similar to the one above. It takes a user-provided object type MyInput.

using Cel.Checker;
using Cel.Tools;

public class MyClass
{
    public bool EvalWithJsonObject(MyInput input, string checkName)
    {
        // Build the script factory
        ScriptHost scriptHost = ScriptHost.NewBuilder()
            .Registry(JsonRegistry.NewRegistry())
            .Build();

        // Create the script, will be parsed and checked.
        // It checks whether the property `Name` in the "Json-ized" class `MyInput` is
        // equal to the value of `checkName`.
        Script script = scriptHost.BuildScript("inp.Name == checkName")
            // Variable declarations - we need `inp` +  `checkName` in this example
            .WithDeclarations(
                Decls.NewVar("inp", Decls.NewObjectType(typeof(MyInput).FullName)),
                Decls.NewVar("checkName", Decls.String))
            // Register our Json-NET object input type
            .WithTypes(typeof(MyInput))
            .Build();

        IDictionary<string, object> arguments = new Dictionary<string, object>();
        arguments.Add("inp", input);
        arguments.Add("checkName", checkName);

        bool result = script.Execute<bool>(arguments);

        return result;
    }

}

Note that the Json.NET field-names are used as property names in Cel.NET. It is not necessary to annotate "plain C#" classes with Json.NET attributes.

Changes from Previous Version

v1.0.0v1.1.0
Added Frameworks
net10.0
Removed Frameworks
net6.0
Added Dependencies
Removed Dependencies

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

Compatibility metadata lists 4 target frameworks; confirm the exact target used by your application.The published metadata declares 28 direct dependency entries across framework groups. Inspect the resolved dependency graph for your target framework.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.