FunctionX 0.3.0

dotnet add package FunctionX --version 0.3.0
                    
NuGet\Install-Package FunctionX -Version 0.3.0
                    
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="FunctionX" Version="0.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FunctionX" Version="0.3.0" />
                    
Directory.Packages.props
<PackageReference Include="FunctionX" />
                    
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 FunctionX --version 0.3.0
                    
#r "nuget: FunctionX, 0.3.0"
                    
#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 FunctionX@0.3.0
                    
#: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=FunctionX&version=0.3.0
                    
Install as a Cake Addin
#tool nuget:?package=FunctionX&version=0.3.0
                    
Install as a Cake Tool

FunctionX

NuGet NuGet Downloads License: MIT .NET Build Status

A high-performance, Excel-compatible formula evaluation engine for .NET applications. FunctionX enables developers to execute Excel-like formulas with dynamic parameters, robust security validation, and comprehensive function support.

โœจ Key Features

  • ๐Ÿ”ง Excel Compatibility: 36 built-in functions matching Excel behavior
  • โšก High Performance: Roslyn-powered compilation with intelligent caching
  • ๐Ÿ›ก๏ธ Security-First: Advanced expression validation with pre-compiled regex patterns
  • ๐ŸŽฏ Type Safety: Full nullable reference type support with comprehensive error handling
  • ๐Ÿ“Š Rich Data Support: Arrays, dictionaries, nested structures, and mixed data types
  • ๐Ÿ”„ Async/Await: Modern asynchronous API design
  • ๐ŸŽช Multi-Platform: Supports .NET 8.0, 9.0, and 10.0 (LTS)

๐Ÿš€ Quick Start

Basic Usage

using FunctionX;

// Simple mathematical expressions
var result = await Fx.EvaluateAsync("1 + 2 * 3"); // Returns: 7

// Excel-style functions
var sum = await Fx.EvaluateAsync("SUM(1, 2, 3, 4, 5)"); // Returns: 15
var average = await Fx.EvaluateAsync("AVERAGE(10, 20, 30)"); // Returns: 20

// New in v0.3.0: Math functions
var sqrt = await Fx.EvaluateAsync("SQRT(16)"); // Returns: 4
var power = await Fx.EvaluateAsync("POWER(2, 10)"); // Returns: 1024
var mod = await Fx.EvaluateAsync("MOD(17, 5)"); // Returns: 2

Working with Parameters

// Using dynamic parameters with @ syntax
var parameters = new Dictionary<string, object?>
{
    { "sales", new[] { 1000, 1500, 2000, 1200 } },
    { "target", 1300 }
};

// Calculate values meeting criteria
var highSales = await Fx.EvaluateAsync("COUNTIF(@sales, \">1300\")", parameters); // Returns: 2
var totalHigh = await Fx.EvaluateAsync("SUMIF(@sales, \">@target\", @sales)", parameters); // Returns: 3500

// New in v0.3.0: AVERAGEIF
var avgHigh = await Fx.EvaluateAsync("AVERAGEIF(@sales, \">1300\")", parameters); // Returns: 1750

// Conditional logic with parameters
var performance = await Fx.EvaluateAsync(
    "IF(AVERAGE(@sales) >= @target, \"Above Target\", \"Below Target\")",
    parameters); // Returns: "Above Target"

Advanced Examples

// Complex nested expressions
var complexResult = await Fx.EvaluateAsync(
    "ROUND(AVERAGE(@data) * 1.15, 2)",
    new Dictionary<string, object?> { { "data", new[] { 85.6, 92.3, 78.9 } } }
); // Returns: 98.42

// Data validation and processing
var validationResult = await Fx.EvaluateAsync(
    "IF(AND(ISNUMBER(@input), NOT(ISBLANK(@input))), ABS(@input), 0)",
    new Dictionary<string, object?> { { "input", -42.5 } }
); // Returns: 42.5

// Text processing
var formatted = await Fx.EvaluateAsync(
    "PROPER(TRIM(@name))",
    new Dictionary<string, object?> { { "name", "  john doe  " } }
); // Returns: "John Doe"

// Math operations (v0.3.0)
var distance = await Fx.EvaluateAsync(
    "SQRT(POWER(@x, 2) + POWER(@y, 2))",
    new Dictionary<string, object?> { { "x", 3 }, { "y", 4 } }
); // Returns: 5

Error Handling

try
{
    var result = await Fx.EvaluateAsync("INVALID_FUNCTION(1, 2)");
}
catch (FxCompilationErrorException ex)
{
    Console.WriteLine($"Formula error: {ex.Message}");
}
catch (FxUnsafeExpressionException ex)
{
    Console.WriteLine($"Security error: {ex.Message}");
}
catch (FxValueException ex)
{
    Console.WriteLine($"Value error: {ex.Message}");
}
catch (FxNumException ex)
{
    Console.WriteLine($"Numeric error: {ex.Message}"); // e.g., SQRT of negative
}
catch (FxDivideByZeroException ex)
{
    Console.WriteLine($"Division error: {ex.Message}"); // e.g., MOD with zero divisor
}

๐Ÿ“‹ Implemented Functions

Category Functions
Mathematical (11) SUM, AVERAGE, MAX, MIN, COUNT, COUNTA, ROUND, ABS, SQRT, POWER, MOD
Conditional (7) COUNTIF, SUMIF, AVERAGEIF, IF, IFS, SWITCH, IFERROR
Logical (4) AND, OR, NOT, XOR
Text (10) CONCAT, LEFT, RIGHT, MID, TRIM, UPPER, LOWER, PROPER, REPLACE, LEN
Data (3) INDEX, VLOOKUP, UNIQUE
Validation (2) ISBLANK, ISNUMBER
Utility (1) INT

Total: 38 Excel-compatible functions

Function Details

Function Description Example
SUM Calculates the sum of numeric values SUM(1, 2, 3) โ†’ 6
AVERAGE Calculates the average of numeric values AVERAGE(10, 20) โ†’ 15
MAX Finds the maximum value MAX(1, 5, 3) โ†’ 5
MIN Finds the minimum value MIN(1, 5, 3) โ†’ 1
COUNT Counts numeric values COUNT(1, "a", 2) โ†’ 2
COUNTA Counts non-empty values COUNTA(1, "a", null) โ†’ 2
ROUND Rounds to decimal places ROUND(3.456, 2) โ†’ 3.46
ABS Returns absolute value ABS(-5) โ†’ 5
SQRT Returns square root SQRT(16) โ†’ 4
POWER Returns number raised to power POWER(2, 3) โ†’ 8
MOD Returns remainder after division MOD(10, 3) โ†’ 1
COUNTIF Counts values meeting condition COUNTIF(@arr, ">5")
SUMIF Sums values meeting condition SUMIF(@arr, ">5")
AVERAGEIF Averages values meeting condition AVERAGEIF(@arr, ">5")
IF Conditional branching IF(true, "Yes", "No") โ†’ "Yes"
IFS Multiple condition check IFS(false, 1, true, 2) โ†’ 2
SWITCH Match value against cases SWITCH(@v, 1, "A", 2, "B")
IFERROR Handle errors gracefully IFERROR(1/0, "Error")
AND Logical AND AND(true, true) โ†’ true
OR Logical OR OR(false, true) โ†’ true
NOT Logical NOT NOT(false) โ†’ true
XOR Logical XOR XOR(true, true) โ†’ false
CONCAT Concatenate strings CONCAT("A", "B") โ†’ "AB"
LEFT Left characters LEFT("Hello", 2) โ†’ "He"
RIGHT Right characters RIGHT("Hello", 2) โ†’ "lo"
MID Middle characters MID("Hello", 2, 3) โ†’ "ell"
TRIM Remove whitespace TRIM(" Hi ") โ†’ "Hi"
UPPER Convert to uppercase UPPER("hi") โ†’ "HI"
LOWER Convert to lowercase LOWER("HI") โ†’ "hi"
PROPER Title case PROPER("john doe") โ†’ "John Doe"
REPLACE Replace substring REPLACE("Hi", "i", "ello") โ†’ "Hello"
LEN String length LEN("Hello") โ†’ 5
INDEX Get value at position INDEX(@arr, 1, 1)
VLOOKUP Vertical lookup VLOOKUP(@key, @range, 2)
UNIQUE Remove duplicates UNIQUE(1, 2, 1) โ†’ [1, 2]
ISBLANK Check if blank ISBLANK(null) โ†’ true
ISNUMBER Check if number ISNUMBER(42) โ†’ true
INT Convert to integer INT(3.7) โ†’ 3

๐Ÿ”ง Performance & Security

Performance Features

  • Compilation Caching: Compiled expressions are cached for repeated use with configurable cache size
  • Pre-compiled Regex: Security patterns use compiled regex for faster validation
  • Optimized Execution: Roslyn-based compilation provides near-native performance
  • Memory Efficient: Automatic cache trimming prevents unbounded memory growth
  • Async Operations: Non-blocking evaluation with full async support
// Cache management
Fx.MaxCacheSize = 500; // Configure max cached expressions (default: 1000)
Fx.ClearCache(); // Clear compilation cache when needed
var (scripts, options) = Fx.GetCacheStatistics(); // Monitor cache usage

Security Features

  • Expression Validation: 60+ pre-compiled regex patterns prevent injection attacks
  • Forbidden Patterns: Blocks access to Process, File, Assembly, Reflection, etc.
  • Length Limits: Expression length validation prevents DoS attacks
  • Sandboxed Execution: Restricted access to system resources
  • Type Safety: Strong typing with nullable reference type support

๐Ÿ“ฆ Installation

Install via NuGet Package Manager:

# .NET CLI
dotnet add package FunctionX

# Package Manager Console
Install-Package FunctionX

# PackageReference
<PackageReference Include="FunctionX" Version="0.3.0" />

๐ŸŽฏ Supported Platforms

  • .NET 8.0 - Long-term support (LTS)
  • .NET 9.0 - Standard term support (STS)
  • .NET 10.0 - Long-term support (LTS) โœจ Latest

Note: Starting from v0.3.0, FunctionX focuses on .NET 8.0+ for improved quality and performance. For older .NET versions, use v0.2.x.

๐Ÿงช Testing & Quality

  • Comprehensive Test Suite: 180+ unit tests covering all functions
  • Edge Case Coverage: Extensive testing of boundary conditions
  • Performance Testing: Validated with large datasets
  • Security Testing: Validation against injection attacks
  • XML Documentation: Full IntelliSense support with XML comments

๐Ÿ“ Changelog

v0.3.0 (2024-2025)

New Features

  • Added SQRT function - square root calculation
  • Added POWER function - exponentiation
  • Added MOD function - modulo with Excel-compatible sign behavior
  • Added AVERAGEIF function - conditional averaging

Improvements

  • Extended target frameworks to .NET 8.0, 9.0, and 10.0 (LTS)
  • Pre-compiled 60+ security regex patterns for faster validation
  • Added configurable cache size limit (MaxCacheSize) with automatic trimming
  • Complete XML documentation for all public APIs
  • DRY refactoring: extracted common criteria parsing logic

Breaking Changes

  • Dropped support for .NET Standard 2.1, .NET 5.0, 6.0, 7.0
  • Minimum supported version is now .NET 8.0
  • Maximum supported version is .NET 10.0 (LTS)

v0.2.x

  • Initial release with 32 Excel-compatible functions
  • Support for .NET Standard 2.1 through .NET 9.0

๐Ÿค Contributing

FunctionX is an open-source project. We welcome contributions!

How to Contribute

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-function)
  3. Commit your changes (git commit -m 'Add amazing function')
  4. Push to the branch (git push origin feature/amazing-function)
  5. Open a Pull Request

Development Setup

git clone https://github.com/iyulab/FunctionX.git
cd FunctionX/src
dotnet build
dotnet test

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

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 is compatible.  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
0.3.0 176 11/27/2025
0.1.13 277 4/2/2024
0.1.12 194 4/1/2024
0.1.11 191 4/1/2024
0.1.10 162 4/1/2024
0.1.9 179 4/1/2024
0.1.6 211 3/30/2024
0.1.5 177 3/26/2024
0.1.4 189 3/26/2024
0.1.3 162 3/26/2024
0.1.2 167 3/26/2024