Dynamically evaluate and interpolate C# expressions at runtime with ease, leveraging a powerful script execution engine.
$ dotnet add package DollarSignEngineDynamically evaluate and interpolate C# expressions at runtime with ease, leveraging a powerful script execution engine.
The DollarSignEngine is a robust C# library designed to simplify the process of dynamically evaluating and interpolating expressions at runtime. Ideal for applications requiring on-the-fly script execution, it offers developers the flexibility to inject variables and execute complex C# expressions seamlessly.
The library is available on NuGet. You can install it using the following command:
dotnet add package DollarSignEngine
Below are some examples of how to use the DollarSignEngine to evaluate expressions dynamically.
Evaluating Simple Expressions
var result = await DollarSign.EvalAsync("1 + 1");
Console.WriteLine(result); // Outputs: 2
Interpolating Strings with Parameters
var parameters = new Dictionary<string, object>
{
{ "name", "John" }
};
var result = await DollarSign.EvalAsync("Hello, {name}", parameters);
Console.WriteLine(result); // Outputs: Hello, John
Handling Complex Data Types
var person = new { FirstName = "Jane", LastName = "Doe" };
var parameters = new Dictionary<string, object>
{
{ "person", person }
};
var result = await DollarSign.EvalAsync("Person: {person.FirstName} {person.LastName}", parameters);
Console.WriteLine(result); // Outputs: Person: Jane Doe
More usage can be found in the test code. Show Tests
Contributions are welcome! If you have an idea for improvement or have found a bug, please feel free to create an issue or submit a pull request.