Skip to content

Commit 413d3c9

Browse files
authored
Merge pull request #36 from codingseb/dev
Version 1.4.0.0
2 parents b135786 + be39335 commit 413d3c9

16 files changed

+1570
-610
lines changed

CodingSeb.ExpressionEvaluator.Tests/CodingSeb.ExpressionEvaluator.Tests.csproj

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,19 @@
1313
<PackageReference Include="Shouldly" Version="3.0.2" />
1414
</ItemGroup>
1515
<ItemGroup>
16-
<Compile Update="OthersTests.cs">
17-
<SubType>Code</SubType>
18-
</Compile>
16+
<Compile Update="OthersTests.cs" />
1917
<Compile Update="Resources.Designer.cs">
2018
<AutoGen>True</AutoGen>
2119
<DesignTime>True</DesignTime>
2220
<DependentUpon>Resources.resx</DependentUpon>
2321
</Compile>
24-
<Compile Update="TestsUtils\ClassStructContainer.cs">
25-
<SubType>Code</SubType>
26-
</Compile>
27-
<Compile Update="TestsUtils\StructForTest3.cs">
28-
<SubType>Code</SubType>
29-
</Compile>
30-
<Compile Update="TestsUtils\StructForTest1.cs">
31-
<SubType>Code</SubType>
32-
</Compile>
33-
<Compile Update="TestsUtils\StructForTest4.cs">
34-
<SubType>Code</SubType>
35-
</Compile>
36-
<Compile Update="TestsUtils\StructForTest2.cs">
37-
<SubType>Code</SubType>
38-
</Compile>
22+
<Compile Update="TestsUtils\ClassStructContainer.cs" />
23+
<Compile Update="TestsUtils\StructForTest3.cs" />
24+
<Compile Update="TestsUtils\StructForTest1.cs" />
25+
<Compile Update="TestsUtils\StructForTest4.cs" />
26+
<Compile Update="TestsUtils\StructForTest2.cs" />
27+
<Compile Update="TestsUtils\XExpressionEvaluator2.cs" />
28+
<Compile Update="TestsUtils\XExpressionEvaluator1.cs" />
3929
</ItemGroup>
4030
<ItemGroup>
4131
<ProjectReference Include="..\CodingSeb.ExpressionEvaluator\CodingSeb.ExpressionEvaluator.csproj" />

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorScriptEvaluateTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,16 @@ public static IEnumerable<TestCaseData> TestCasesForScriptEvaluateTests
12191219

12201220
#endregion
12211221

1222+
#region var keyword
1223+
1224+
yield return new TestCaseData(Resources.Script0060, null, null, null)
1225+
.SetCategory("Script")
1226+
.SetCategory("var keyword")
1227+
.SetCategory("=")
1228+
.Returns("A text for 4 test");
1229+
1230+
#endregion
1231+
12221232
#region More complex script
12231233

12241234
yield return new TestCaseData(Resources.Script0007, null, null, null)

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

Lines changed: 440 additions & 30 deletions
Large diffs are not rendered by default.

CodingSeb.ExpressionEvaluator.Tests/Resources.Designer.cs

Lines changed: 22 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CodingSeb.ExpressionEvaluator.Tests/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,7 @@
295295
<data name="Script0059" type="System.Resources.ResXFileRef, System.Windows.Forms">
296296
<value>resources\script0059.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
297297
</data>
298+
<data name="Script0060" type="System.Resources.ResXFileRef, System.Windows.Forms">
299+
<value>resources\script0060.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
300+
</data>
298301
</root>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* Script0060 */
2+
var x = 4;
3+
var textVar = "A text for {0} test";
4+
5+
return string.Format(textVar, x);

CodingSeb.ExpressionEvaluator.Tests/TestsUtils/ClassForTest1.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public class ClassForTest1
1212

1313
public static int StaticIntProperty { get; set; } = 67;
1414

15+
public int PropertyThatWillFailed { get; set; } = 1;
16+
1517
public int Add3To(int value)
1618
{
1719
return value + 3;
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 XExpressionEvaluator1 : ExpressionEvaluator
4+
{
5+
protected override void Init()
6+
{
7+
operatorsDictionary.Add("and", ExpressionOperator.ConditionalAnd);
8+
operatorsDictionary.Add("or", ExpressionOperator.ConditionalOr);
9+
operatorsDictionary.Remove("&&");
10+
operatorsDictionary.Remove("||");
11+
}
12+
}
13+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace CodingSeb.ExpressionEvaluator.Tests
6+
{
7+
public class XExpressionEvaluator2 : ExpressionEvaluator
8+
{
9+
protected new static readonly IList<ExpressionOperator> leftOperandOnlyOperatorsEvaluationDictionary =
10+
ExpressionEvaluator.leftOperandOnlyOperatorsEvaluationDictionary
11+
.ToList()
12+
.FluidAdd(XExpressionOperator2.Sharp);
13+
14+
//protected new static readonly IList<ExpressionOperator> rightOperandOnlyOperatorsEvaluationDictionary =
15+
// ExpressionEvaluator.rightOperandOnlyOperatorsEvaluationDictionary
16+
// .ToList();
17+
18+
protected new static readonly IList<IDictionary<ExpressionOperator, Func<dynamic, dynamic, object>>> operatorsEvaluations =
19+
ExpressionEvaluator.operatorsEvaluations
20+
.Copy()
21+
.AddOperatorEvaluationAtNewLevelAfter(XExpressionOperator2.Sharp, (left, _) => Math.Pow(left, -left), ExpressionOperator.UnaryPlus)
22+
.AddOperatorEvaluationAtLevelOf(XExpressionOperator2.Love, (left, right) => (left | right) << 1, ExpressionOperator.ShiftBitsLeft);
23+
24+
protected override IList<ExpressionOperator> LeftOperandOnlyOperatorsEvaluationDictionary => leftOperandOnlyOperatorsEvaluationDictionary;
25+
26+
// protected override IList<ExpressionOperator> RightOperandOnlyOperatorsEvaluationDictionary => rightOperandOnlyOperatorsEvaluationDictionary;
27+
28+
protected override IList<IDictionary<ExpressionOperator, Func<dynamic, dynamic, object>>> OperatorsEvaluations => operatorsEvaluations;
29+
30+
protected override void Init()
31+
{
32+
operatorsDictionary.Add("#", XExpressionOperator2.Sharp);
33+
operatorsDictionary.Add("love", XExpressionOperator2.Love);
34+
}
35+
}
36+
37+
public class XExpressionOperator2 : ExpressionOperator
38+
{
39+
public static readonly ExpressionOperator Sharp = new XExpressionOperator2();
40+
public static readonly ExpressionOperator Love = new XExpressionOperator2();
41+
}
42+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text.RegularExpressions;
4+
5+
namespace CodingSeb.ExpressionEvaluator.Tests
6+
{
7+
public class XExpressionEvaluator3 : ExpressionEvaluator
8+
{
9+
protected override void Init()
10+
{
11+
ParsingMethods.Insert(0, EvaluateDateTimeSyntax);
12+
ParsingMethods.Add(EvaluateSpecialTernaryOperator);
13+
}
14+
15+
/// <summary>
16+
/// To evaluate DateTimes objects with #year-month-day syntax (#2019-05-28)
17+
/// </summary>
18+
protected virtual bool EvaluateDateTimeSyntax(string expression, Stack<object> stack, ref int i)
19+
{
20+
Match match = Regex.Match(expression.Substring(i), @"^\s*#(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})");
21+
22+
if(match.Success)
23+
{
24+
int year = int.Parse(match.Groups["year"].Value);
25+
int month = int.Parse(match.Groups["month"].Value);
26+
int day = int.Parse(match.Groups["day"].Value);
27+
28+
DateTime dateTime = new DateTime(year,month, day);
29+
30+
stack.Push(dateTime);
31+
32+
i += match.Length - 1;
33+
34+
return true;
35+
}
36+
37+
return false;
38+
}
39+
40+
/// <summary>
41+
/// To evaluate a string replace with custom ternary indicator
42+
/// </summary>
43+
protected virtual bool EvaluateSpecialTernaryOperator(string expression, Stack<object> stack, ref int i)
44+
{
45+
if (expression.Substring(i, 1).Equals("°"))
46+
{
47+
string input = (string)ProcessStack(stack);
48+
49+
string restOfExpression = expression.Substring(i + 1);
50+
51+
for (int j = 0; j < restOfExpression.Length; j++)
52+
{
53+
string s2 = restOfExpression.Substring(j, 1);
54+
55+
Match internalStringMatch = stringBeginningRegex.Match(restOfExpression.Substring(j));
56+
57+
if (internalStringMatch.Success)
58+
{
59+
string innerString = internalStringMatch.Value + GetCodeUntilEndOfString(restOfExpression.Substring(j + internalStringMatch.Length), internalStringMatch);
60+
j += innerString.Length - 1;
61+
}
62+
else if (s2.Equals("("))
63+
{
64+
j++;
65+
GetExpressionsBetweenParenthesesOrOtherImbricableBrackets(restOfExpression, ref j, false);
66+
}
67+
else if (s2.Equals("@"))
68+
{
69+
stack.Clear();
70+
71+
stack.Push(input.Replace((string)Evaluate(restOfExpression.Substring(1, j - 1)), (string)Evaluate(restOfExpression.Substring(j + 1))));
72+
73+
i = expression.Length;
74+
75+
return true;
76+
}
77+
}
78+
}
79+
80+
return false;
81+
}
82+
}
83+
}

CodingSeb.ExpressionEvaluator/CodingSeb.ExpressionEvaluator.csproj

Lines changed: 13 additions & 8 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.3.7.0</Version>
9-
<AssemblyVersion>1.3.7.0</AssemblyVersion>
10-
<FileVersion>1.3.7.0</FileVersion>
8+
<Version>1.4.0.0</Version>
9+
<AssemblyVersion>1.4.0.0</AssemblyVersion>
10+
<FileVersion>1.4.0.0</FileVersion>
1111
<OutputPath>bin\$(Configuration)\</OutputPath>
1212
<Authors>Coding Seb</Authors>
1313
<PackageId>CodingSeb.ExpressionEvaluator</PackageId>
@@ -18,11 +18,16 @@
1818
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1919
<PackageIconUrl>https://github.com/codingseb/ExpressionEvaluator/blob/master/Icon.png?raw=true</PackageIconUrl>
2020
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
21-
<PackageReleaseNotes>* Initialisation of ExpandoObjects
22-
* Create Anonymous (as ExpandoObjects)
23-
* Better management of struct assignation
24-
* Less memory impact when compare string ignoring case
25-
* Correction of some bugs when using OptionForceIntegerNumbersEvaluationsAsDoubleByDefault = true</PackageReleaseNotes>
21+
<PackageReleaseNotes>Warning some breaking changes in the on the fly variables and function evaluations.
22+
Deep changes to allow more customization
23+
24+
* Custom operators or custom expression parsing with inheritance
25+
* Manage &lt;&gt; in on the fly evaluations to evaluate generic types
26+
* 2 additional on the fly evaluation (Preevaluation)
27+
* optionally use var before variable assignation (For better copy paste with C# code)
28+
* option to globally cache namespaces and types resolution (to speed up multiple evaluation)
29+
* Correction of Array/collection indexing when using OptionForceIntegernumbersEvaluationsAsDoubleDyDefault=true
30+
* Some other corrections and refactorings</PackageReleaseNotes>
2631
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
2732
</PropertyGroup>
2833
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

0 commit comments

Comments
 (0)