Skip to content

Enhance NCalc extensions with async support and tests#18

Open
gregbowyer84 wants to merge 7 commits intopanoramicdata:mainfrom
agile-north:ncalc-async
Open

Enhance NCalc extensions with async support and tests#18
gregbowyer84 wants to merge 7 commits intopanoramicdata:mainfrom
agile-north:ncalc-async

Conversation

@gregbowyer84
Copy link
Copy Markdown

  • Updated InterClassTests to expect double instead of decimal and added StringConcat option.
  • Modified IsSetTests to check for null or whitespace instead of empty strings.
  • Changed expected exception in ToDateTimeTests from ArgumentException to NCalcParameterNotDefinedException.
  • Refactored ExtendedExpression constructor for readability and introduced TidyExpression().
  • Replaced FunctionArgs with IFunctionArgs across multiple files for consistency.
  • Introduced AsyncExpressionWrapper, AsyncExtendedExpression, and AsyncFunctionArgsWrapper for async evaluation.
  • Enhanced ExpressionHelper for better parameter configuration and count checking.
  • Updated project dependencies to use NCalc.Core, NCalcAsync, and NCalcSync.
  • Added MaxTestsAsync for testing maximum value calculations with async expressions.
  • Updated GlobalUsings.cs to include new namespaces for async functionality.

- Updated `InterClassTests` to expect `double` instead of `decimal` and added `StringConcat` option.
- Modified `IsSetTests` to check for null or whitespace instead of empty strings.
- Changed expected exception in `ToDateTimeTests` from `ArgumentException` to `NCalcParameterNotDefinedException`.
- Refactored `ExtendedExpression` constructor for readability and introduced `TidyExpression()`.
- Replaced `FunctionArgs` with `IFunctionArgs` across multiple files for consistency.
- Introduced `AsyncExpressionWrapper`, `AsyncExtendedExpression`, and `AsyncFunctionArgsWrapper` for async evaluation.
- Enhanced `ExpressionHelper` for better parameter configuration and count checking.
- Updated project dependencies to use `NCalc.Core`, `NCalcAsync`, and `NCalcSync`.
- Added `MaxTestsAsync` for testing maximum value calculations with async expressions.
- Updated `GlobalUsings.cs` to include new namespaces for async functionality.
- Changed `_expression` and `_args` fields to readonly in
  `AsyncExpressionWrapper`, `AsyncFunctionArgsWrapper`,
  `ExpressionWrapper`, and `FunctionArgsWrapper` classes
  to prevent reassignment after initialization.

- Updated error handling for reserved keywords in
  `ExpressionHelper` to improve readability.

- Removed commented-out generic `Evaluate` method in
  `Lambda` class for code cleanup.
@gregbowyer84
Copy link
Copy Markdown
Author

gregbowyer84 commented Apr 28, 2025

Decided to make support for the new Official NCalc nugets Async and Sync in my fork. Created this PR in case you were keen to bring this into your's?
https://www.nuget.org/packages/NCalc.Core/5.4.1/

The async implementation is currently just calling into the sync functions now for compatibility. I wanted to make support for it first to support the new nuget, and then change the functions to fully support async.

- Replaced `ExtendAsync` with synchronous `Extend` method in `ExpressionHelper`.
- Added new constructors to `AsyncExtendedExpression` and `ExtendedExpression` to accept context parameters for `CultureInfo`.
- Updated event handlers to use the new `Extend` method with context's `CultureInfo`.
- Incremented version number from `3.2` to `3.3` in `version.json`.
Introduces `AsyncExtendedExpressionTests` with two tests to validate the behavior of adding reserved keywords in expressions. Refactors the `Configure` method in `ExpressionHelper.cs` to use a centralized dictionary for managing reserved keywords, improving clarity and maintainability. Updates `using` directives to include `System.Threading.Tasks` for potential asynchronous operations.
Updated test methods in AsyncExtendedExpressionTests.cs to simplify implementations and adjust static parameters for reserved keywords. Enhanced error handling in ExpressionHelper.cs by adding an exception for reserved keyword usage in parameters.
Introduce asynchronous functionality in the NCalc library, enhancing the `AsyncExtendedExpressionTests` and `ExtendedExpressionTests` with tests for custom async functions. Modify `AsyncExpressionWrapper` to improve async expression evaluation and update `ExpressionHelper` for better async function handling. These changes improve the library's flexibility and usability in non-blocking scenarios.
Added braces around return statements in if conditions
to enhance code clarity and explicitly define scope.
@Bykiev
Copy link
Copy Markdown

Bykiev commented Aug 6, 2025

@davidnmbond, can you please review this PR as CoreCLR-NCalc project is archived now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants