Skip to content

Commit 5c9de53

Browse files
author
Sébastien Geiser
committed
Custom Operators in progress
1 parent f4ec3f9 commit 5c9de53

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
<Compile Update="TestsUtils\StructForTest2.cs">
3737
<SubType>Code</SubType>
3838
</Compile>
39+
<Compile Update="TestsUtils\XExpressionEvaluator2.cs">
40+
<SubType>Code</SubType>
41+
</Compile>
3942
<Compile Update="TestsUtils\XExpressionEvaluator1.cs">
4043
<SubType>Code</SubType>
4144
</Compile>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace CodingSeb.ExpressionEvaluator.Tests
2+
{
3+
public class XExpressionEvaluator2 : ExpressionEvaluator
4+
{
5+
protected override void Init()
6+
{
7+
operatorsDictionary.Add("#", XExpressionOperator2.Sharp);
8+
operatorsDictionary.Add("love", XExpressionOperator2.Love);
9+
}
10+
}
11+
12+
public class XExpressionOperator2 : ExpressionOperator
13+
{
14+
public static readonly ExpressionOperator Sharp = new XExpressionOperator2();
15+
public static readonly ExpressionOperator Love = new XExpressionOperator2();
16+
}
17+
}

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,7 +2629,7 @@ protected virtual object ProcessStack(Stack<object> stack)
26292629
{
26302630
ExpressionOperator eOp = operatorEvalutationsDict.Keys.ToList()[opi];
26312631

2632-
if ((list[i] as ExpressionOperator ) == eOp)
2632+
if ((list[i] as ExpressionOperator) == eOp)
26332633
{
26342634
if (rightOperandOnlyOperatorsEvaluationDictionary.ContainsKey(eOp))
26352635
{
@@ -2648,7 +2648,7 @@ protected virtual object ProcessStack(Stack<object> stack)
26482648
list[i] = operatorEvalutationsDict[eOp]((dynamic)list[i + 1], (dynamic)list[i - 1]);
26492649
list.RemoveAt(i + 1);
26502650
list.RemoveAt(i - 1);
2651-
i -= 1;
2651+
i--;
26522652
break;
26532653
}
26542654
}
@@ -3372,11 +3372,6 @@ protected ExpressionOperator()
33723372
OperatorValue = indexer;
33733373
}
33743374

3375-
protected ExpressionOperator(uint value)
3376-
{
3377-
OperatorValue = value;
3378-
}
3379-
33803375
protected uint OperatorValue { get; }
33813376

33823377
public static readonly ExpressionOperator Plus = new ExpressionOperator();

0 commit comments

Comments
 (0)