Skip to content

Commit ed39cbc

Browse files
authored
Merge pull request #46 from codingseb/dev
Dev
2 parents bca761c + 7e40497 commit ed39cbc

File tree

5 files changed

+200
-108
lines changed

5 files changed

+200
-108
lines changed

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,44 @@ void Evaluator_PreEvaluateVariable(object sender, VariablePreEvaluationEventArg
17421742

17431743
#endregion
17441744

1745+
#region with Context object
1746+
1747+
ExpressionEvaluator evaluatorWithContext = new ExpressionEvaluator(new ContextObject1());
1748+
1749+
yield return new TestCaseData(evaluatorWithContext
1750+
, "AIntValue"
1751+
, null)
1752+
.Returns(3)
1753+
.SetCategory("Context object");
1754+
1755+
yield return new TestCaseData(evaluatorWithContext
1756+
, "SayHelloTo(\"Bob\")"
1757+
, null)
1758+
.Returns("Hello Bob")
1759+
.SetCategory("Context object");
1760+
1761+
ExpressionEvaluator evaluatorWithPersonContext = new ExpressionEvaluator();
1762+
1763+
evaluatorWithPersonContext.Context = new Person1()
1764+
{
1765+
name = "John",
1766+
LastName = "Smith"
1767+
};
1768+
1769+
yield return new TestCaseData(evaluatorWithPersonContext
1770+
, "name + \" \" + LastName"
1771+
, null)
1772+
.Returns("John Smith")
1773+
.SetCategory("Context object");
1774+
1775+
yield return new TestCaseData(evaluatorWithPersonContext
1776+
, "APersonMethod() + 10"
1777+
, null)
1778+
.Returns(20)
1779+
.SetCategory("Context object");
1780+
1781+
#endregion
1782+
17451783
#region inherits ExpressionEvaluator
17461784

17471785
#region Redefine existing operators
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace CodingSeb.ExpressionEvaluator.Tests
2+
{
3+
public class ContextObject1
4+
{
5+
public int AIntValue { get; set; } = 3;
6+
7+
public string SayHelloTo(string name)
8+
{
9+
return "Hello " + name;
10+
}
11+
}
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace CodingSeb.ExpressionEvaluator.Tests
2+
{
3+
public class Person1
4+
{
5+
public string name;
6+
public string LastName { get; set; }
7+
8+
public int APersonMethod()
9+
{
10+
return 10;
11+
}
12+
}
13+
}

CodingSeb.ExpressionEvaluator/CodingSeb.ExpressionEvaluator.csproj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<Product>CodingSeb.ExpressionEvaluator</Product>
66
<Description>A Simple Math and Pseudo C# Expression Evaluator in One C# File. Can also execute small C# like scripts</Description>
77
<Copyright>Copyright © Coding Seb 2017</Copyright>
8-
<Version>1.4.5.0</Version>
9-
<AssemblyVersion>1.4.5.0</AssemblyVersion>
10-
<FileVersion>1.4.5.0</FileVersion>
8+
<Version>1.4.6.0</Version>
9+
<AssemblyVersion>1.4.6.0</AssemblyVersion>
10+
<FileVersion>1.4.6.0</FileVersion>
1111
<OutputPath>bin\$(Configuration)\</OutputPath>
1212
<Authors>Coding Seb</Authors>
1313
<PackageId>CodingSeb.ExpressionEvaluator</PackageId>
@@ -18,8 +18,7 @@
1818
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1919
<PackageIconUrl>https://github.com/codingseb/ExpressionEvaluator/blob/master/Icon.png?raw=true</PackageIconUrl>
2020
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
21-
<PackageReleaseNotes>* myList.ForEach(v =&gt; ...) now working
22-
* Methods that has Action or Action&lt;...&gt; arguments now working</PackageReleaseNotes>
21+
<PackageReleaseNotes>* Add a Context object in addition to variables dictionnary on which properties, fields and method are available directly.</PackageReleaseNotes>
2322
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
2423
</PropertyGroup>
2524
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

0 commit comments

Comments
 (0)