AltaSoft.Simpra.Metadata 1.0.16

dotnet add package AltaSoft.Simpra.Metadata --version 1.0.16
                    
NuGet\Install-Package AltaSoft.Simpra.Metadata -Version 1.0.16
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AltaSoft.Simpra.Metadata" Version="1.0.16" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AltaSoft.Simpra.Metadata" Version="1.0.16" />
                    
Directory.Packages.props
<PackageReference Include="AltaSoft.Simpra.Metadata" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AltaSoft.Simpra.Metadata --version 1.0.16
                    
#r "nuget: AltaSoft.Simpra.Metadata, 1.0.16"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AltaSoft.Simpra.Metadata@1.0.16
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AltaSoft.Simpra.Metadata&version=1.0.16
                    
Install as a Cake Addin
#tool nuget:?package=AltaSoft.Simpra.Metadata&version=1.0.16
                    
Install as a Cake Tool

AltaSoft.Simpra

Version Dot NET 8+

Simpra is a powerful expression language designed for evaluating dynamic expressions in .NET applications. It enables developers to execute logic dynamically within their applications, similar to how scripting languages work but optimized for business rules.

Installation

To install AltaSoft.Simpra, use NuGet:

dotnet add package AltaSoft.Simpra

Or in your .csproj:

<PackageReference Include="AltaSoft.Simpra" Version="1.0.0" />

Features

  • Dynamic Expression Execution: Evaluate expressions at runtime.
  • Rich Syntax: Conditionals, arithmetic, lists, pattern matching, regex, membership, null checks.
  • Mutability Control: Toggle between immutable and mutable execution.
  • String & List Operations: Manipulate and aggregate data easily.
  • Custom Functions: Extend with user-defined or async functions.
  • Safe Evaluation: No loops, recursion, or external resource access.

Language Specifics

Supported Operators

  • Arithmetic
    +, -, *, /, // (integer division), postfix % (percent), min, max

    10 // 3     # 3
    50%        # 0.5
    5 min 2    # 2
    
  • Comparison
    is, is not, <, <=, >, >=

    x is 10
    y is not null
    a < b and < c   # chained comparison
    
  • Logical
    and, or, not

  • Membership
    in, not in, plus any in, all in, any not in, all not in

    x in [1, 2, 3]
    all in [true, true, false]
    
  • Pattern Matching

    • matches (regex)
    • like (SQL-like patterns)
    email matches "[a-z]+@[a-z]+\\.[a-z]+"
    name like "Jo%"
    
  • Null Handling
    has value

    nullable has value
    

Control Flow

  • if … then … else … end
  • when … then … else … end
  • return
if x > 10 then
    return "big"
else
    return "small"
end

when color then
    "red"   -> "Stop"
    "green" -> "Go"
    else "Unknown"
end

Directives

Simpra supports runtime directives that influence evaluation:

  • $mutable on/off – Enables or disables mutability for model properties (local variables are always mutable).
  • $case_sensitive on/off – Controls case sensitivity in string comparisons (is, like, matches).

Example:

let str = 'abc'
$case_sensitive off
return str like 'A%'    # true

Variables & Mutability

  • Local variables declared with let are always mutable:

    let x = 10
    x += 5    # 15
    x -= 2    # 13
    
  • Model properties can only be reassigned if mutability is enabled with $mutable on:

    $mutable on
    Transfer.Amount = Transfer.Amount + 50
    
  • By default, $mutable is off, meaning model properties are read-only.


Lists

let items = [1, 2, 3]
items[0]         # 1
sum(items)       # 6
length(items)    # 3

Functions & Access

  • Function calls: method("hi")
  • Properties: obj.prop
  • Indexers: list[1]

Chained Comparisons

Simpra supports chained comparison expressions without repeating the left-hand operand:

let x = 5
return x > 0 and < 10    # true

This allows constructs like a < b and < c for concise range checks.


Built-in Functions

Simpra provides a set of internal functions out-of-the-box:

  • Math

    • abs(x) – absolute value
    • round(x) – round to nearest integer
    • min(a, b, …), max(a, b, …) – smallest/largest value
  • Lists

    • sum(list) – sum of values
    • length(list) – number of elements
  • Strings

    • number(str) – converts to number
    • date(str) – converts to date
    • substring(str, index, count) – Retrieves part of a string starting at a 1-based position.

Extended Membership Operators

In addition to in and not in, Simpra supports any in, all in, any not in, and all not in:

let values = [1, 2, 3]

2 any in values       # true
[2, 4] all in values  # false
2 any not in values   # false
[4, 5] all not in values  # true

Percent Operator

The % operator in Simpra is postfix percent, not modulus.

50%     # 0.5
200%    # 2.0

This makes it easy to express percentages directly inside formulas.

Usage

Evaluating Simple Expressions

var simpra = new Simpra();
var model = new TestModel { Transfer = new Transfer { Amount = 50, Currency = "USD" } };

const string expression = "return Transfer.Amount * 2";
var result = simpra.Execute<int, TestModel>(model, expression);

Console.WriteLine(result); // Output: 100

Conditionals & Logical Operators

const string expression = """
let transfer = Transfer
return transfer.Amount > 100 and transfer.Currency is 'USD'
""";

var result = simpra.Execute<bool, TestModel>(model, expression);
Console.WriteLine(result); // Output: false

Handling Lists & Aggregations

const string expression = """
let values = [10, 20, 30]
return sum(values) / length(values)
""";

var result = simpra.Execute<decimal, TestModel>(model, expression);
Console.WriteLine(result); // Output: 20

Using Regular Expressions

const string expression = """
let value = 'abc123'
return value matches '[a-zA-Z_][a-zA-Z_0-9]*'
""";

var result = simpra.Execute<bool, TestModel>(model, expression);
Console.WriteLine(result); // Output: true

Safe Division with when

const string expression = """
let amount = Transfer.Amount
let divisor = 0
let result = when divisor is not 0 then amount / divisor else 0 end
return result
""";

var result = simpra.Execute<int, TestModel>(model, expression);
Console.WriteLine(result); // Output: 0

String Manipulation

const string expression = """
let str = 'hello'
return Upper(str) + ' WORLD'
""";

var result = simpra.Execute<string, TestModel, TestFunctions>(model, new TestFunctions(), expression);
Console.WriteLine(result); // Output: "HELLO WORLD"

Arithmetic Operators (//, %, min, max)

const string expression = """
let a = 10
let b = 3
let half = 50%
return [ a // b, half, a min b, a max b ]
""";

var result = simpra.Execute<List<decimal>, TestModel>(model, expression);
Console.WriteLine(string.Join(", ", result)); // Output: "3, 0.5, 3, 10"

Advanced Features

Mutable vs Immutable Execution

By default, expressions in Simpra are immutable. However, you can enable mutability:

const string expression = """
$mutable on
let x = 10
x = x + 5
return x
""";

var result = simpra.Execute<int, TestModel>(model, expression);
Console.WriteLine(result); // Output: 15

Custom Functions

You can define custom functions and use them in expressions:

public class CustomFunctions
{
    public static string Reverse(string input) => new string(input.Reverse().ToArray());
}

const string expression = "return Reverse('hello')";
var result = simpra.Execute<string, TestModel, CustomFunctions>(model, new CustomFunctions(), expression);
Console.WriteLine(result); // Output: "olleh"

Async Method Execution

Simpra supports calling asynchronous methods within expressions:

public class AsyncFunctions
{
    public async Task<int> GetExchangeRateAsync() => await Task.FromResult(3);
}

const string expression = "return GetExchangeRateAsync() * 10";
var result = await simpra.ExecuteAsync<int, TestModel, AsyncFunctions>(model, new AsyncFunctions(), expression);

Console.WriteLine(result); // Output: 30

Mutability: Modifying Class Properties

Mutability can be enabled to allow modifying object properties:

const string expression = @"
$mutable on
Transfer.Amount = Transfer.Amount + 50
return true
";

var model = new TestModel { Transfer = new Transfer { Amount = 100 } };
var result = simpra.Execute<bool, TestModel>(model, expression);

Console.WriteLine(result); // Output: true
Console.WriteLine(model.Transfer.Amount); // Output: 150

License

AltaSoft.Simpra is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.16 205 9/23/2025
1.0.15 524 7/2/2025
1.0.14 213 5/28/2025
1.0.13 171 5/27/2025
1.0.12 188 5/5/2025
1.0.11 161 5/5/2025
1.0.10 168 5/5/2025
1.0.9 304 4/24/2025
1.0.7 187 4/24/2025
1.0.6 226 4/16/2025
1.0.5 211 4/15/2025
1.0.4 216 4/15/2025
1.0.3 154 4/11/2025
1.0.2 161 3/28/2025
1.0.1 499 3/26/2025
1.0.0 208 3/20/2025