Skip to content

Commit

Permalink
Document reusable operations
Browse files Browse the repository at this point in the history
  • Loading branch information
miroiu authored Dec 4, 2020
1 parent 9f76762 commit 19fcf85
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,34 @@ decimal result = myCalculator.Evaluate("2 * 3 max 4"); // 8

### Creating and using variables
```csharp
// Creating a variables collection
Replacements variables = new Replacements
{
["a"] = 5,
["PI"] = 3.1415926535897931
};

Calculator myCalculator = new Calculator(variables);
Calculator myCalculator = new Calculator(variables); // default variables collection is optional (can still add variables without a collection)
// Replacing existing variables
// Replacing or creating variables
myCalculator.Replace("a", 2);
myCalculator.Replace("b", 1);
myCalculator.Replace("b", 1); // new syntax: myCalculator["b"] = 1;
decimal result = calculator.Evaluate("{a} + 2 * {b} + {PI}"); // 7.1415926535897931
```

### Creating and reusing operations
```csharp
myCalculator["a"] = 5;

// Creating operations
OperationInfo op = myCalculator.CreateOperation("2 * {a}");
decimal result1 = myCalculator.Evaluate(op); // 10
// Reusing the operation (improves performance)
myCalculator["a"] = 3;
decimal result2 = myCalculator.Evaluate(op); // 6
```

### Using the static api: SMath
```csharp
// Same API as a calculator instance except the Evaluate method
Expand Down

0 comments on commit 19fcf85

Please sign in to comment.