uCalc API Version: 5.7.0-preview.1 Released: 7/30/2026
Warning
uCalc API Preview Release Notice:This preview documentation describes the intended behavior of the API. It is not fully accurate or complete.The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.Use of the preview version in your production code is not recommended.
Product:
Class:
Creates an identical, yet completely independent, copy of a parsed expression object.
A new, independent Expression object that is a complete replica of the original.
The Clone method creates a deep, independent copy of a parsed Expression object. This is a highly efficient operation, as it duplicates the internal Abstract Syntax Tree (AST) directly in memory, which is significantly faster than re-parsing the original expression string.
Cloning a parsed expression is essential for several advanced scenarios:
Performance Optimization: The most common use case. Parsing a complex expression string can be computationally expensive. If you need to evaluate the same logic repeatedly (e.g., inside a loop or across different parts of your application), you should parse it once with uCalc.Parse, and then Clone the resulting Expression object as needed. This avoids the high cost of repeated parsing.
Preserving an Original Template: You can treat a parsed expression as a master template. If you need to experiment with it (e.g., with potential future APIs that might modify the expression tree), you can work on a clone, leaving the original intact.
Expression.Clone() vs. uCalc.Clone()It is important to understand the distinction between cloning an expression and cloning the entire uCalc engine:
Expression.Clone(): Copies a single parsed expression. The clone still relies on the original uCalc instance to resolve variables and functions during evaluation.A cloned Expression object, like one created with Parse, holds onto memory and should be released when no longer needed. This can be done explicitly with Release() or automatically using language-specific scoping constructs like using in C# or Owned in C++, as shown in the examples.