Skip to content

Commit fa64679

Browse files
authored
Merge pull request #37 from navtech-io/develop
Fix indexer issue
2 parents ca1a4c6 + 3921ee0 commit fa64679

File tree

6 files changed

+50
-15
lines changed

6 files changed

+50
-15
lines changed

src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.Helpers.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,23 @@ private Expression GetNumberExpression(string value)
2222

2323
private Expression GetNumberExpression(string value, Type targetType)
2424
{
25-
if (targetType == typeof(int) ||
26-
targetType == typeof(long) ||
27-
targetType == typeof(decimal) ||
28-
targetType == typeof(double) ||
29-
targetType == typeof(float) ||
30-
targetType == typeof(object) ||
31-
targetType == typeof(byte))
25+
if ( targetType == typeof(long)
26+
|| targetType == typeof(ulong)
27+
28+
|| targetType == typeof(int)
29+
|| targetType == typeof(uint)
30+
31+
|| targetType == typeof(short)
32+
|| targetType == typeof(ushort)
33+
34+
|| targetType == typeof(byte)
35+
|| targetType == typeof(sbyte)
36+
37+
|| targetType == typeof(decimal)
38+
|| targetType == typeof(double)
39+
|| targetType == typeof(float)
40+
41+
|| targetType == typeof(object) )
3242
{
3343
return Expression.Constant(Convert.ChangeType(value, targetType), targetType);
3444
}

src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.VisitObjectIdentifier.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ private Expression GetFinalPropertyValue(Expression propExp, SimpleflowParser.Id
8282
}
8383
}
8484

85-
// Get indexed object
86-
propExp = GetIndexObjectExpIfDefined(propExp, property.index());
87-
8885
// Get property of indexed object
8986
if (prop != null)
9087
{
@@ -94,6 +91,10 @@ private Expression GetFinalPropertyValue(Expression propExp, SimpleflowParser.Id
9491
{
9592
propExp = Expression.Field(propExp, field);
9693
}
94+
95+
// Get indexed object
96+
propExp = GetIndexObjectExpIfDefined(propExp, property.index());
97+
9798
}
9899
return propExp;
99100
}

src/Simpleflow/RuntimeContext.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,28 @@ public sealed class RuntimeContext
1414
readonly FlowOutput _flowOutput;
1515
readonly CancellationToken _token;
1616

17-
private RuntimeContext() { }
18-
1917
internal RuntimeContext(FlowOutput flowOutput, CancellationToken token)
2018
{
2119
_flowOutput = flowOutput;
2220
_token = token;
2321
}
2422

23+
/// <summary>
24+
/// Gets true if errors are emitted else false.
25+
/// </summary>
2526
public bool HasErrors => _flowOutput.Errors.Count > 0;
27+
28+
/// <summary>
29+
/// Gets true if messages are emitted else false.
30+
/// </summary>
2631
public bool HasMessages => _flowOutput.Messages.Count > 0;
2732

2833
[Obsolete(null, true)]
2934
public bool HasOutputs => _flowOutput.Output.Count > 0;
35+
36+
/// <summary>
37+
/// Gets cancellation token
38+
/// </summary>
3039
public CancellationToken CancellationToken => _token;
3140
}
3241
}

src/Simpleflow/Simpleflow.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<TargetFrameworks>net48;netcoreapp3.1;net6.0;</TargetFrameworks>
44
<PackageIcon>PackageIcon.png</PackageIcon>
55
<VersionPrefix>1.0.12</VersionPrefix>
6-
<VersionSuffix>beta1</VersionSuffix>
6+
<VersionSuffix>beta2</VersionSuffix>
77
<PackageReadmeFile>README.md</PackageReadmeFile>
88
</PropertyGroup>
99

src/Simpleflow/Simpleflow.xml

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

test/Simpleflow.Tests/Scripting/PredicateStatementsTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ public void CheckShortCircuitingAndOperatorWithFunctions()
187187
// Arrange
188188
var script =
189189
@"
190-
rule when $exists(dict: arg, key: 'ContentType') and $str(value: arg['ContentType']) in ['test'] then
190+
rule when $exists(dict: arg.data, key: 'ContentType') and $str(value: arg.data['ContentType']) in ['test'] then
191191
message 'got it'
192192
";
193193

194194
FlowOutput output = SimpleflowEngine.Run(script,
195-
new Dictionary<string, object> { { "ContentType", "test" } }
195+
new { Data = new Dictionary<string, object> { { "ContentType", "test" } } }
196196
,
197197
new FunctionRegister().Add("exists", (System.Func<IDictionary<string, object>, string, bool>)Exists));
198198

0 commit comments

Comments
 (0)