Skip to content

Commit

Permalink
rolled back
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Sulwer committed Jun 21, 2024
1 parent 8547360 commit 04c51f5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
8 changes: 4 additions & 4 deletions demo/DemoApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public static async Task Main(string[] args)
//initiate cancel, set to something lower than time it takes for program to complete to initiate cancel
//cts.CancelAfter(TimeSpan.FromMilliseconds(94));

//await new Demos.Basic().Run(cts.Token);
//await new Demos.JSON().Run(cts.Token);
//await new Demos.NestedInput().Run(cts.Token);
//await new Demos.EF().Run(cts.Token);
await new Demos.Basic().Run(cts.Token);
await new Demos.JSON().Run(cts.Token);
await new Demos.NestedInput().Run(cts.Token);
await new Demos.EF().Run(cts.Token);
await new Demos.UseFastExpressionCompiler().Run(cts.Token);
}

Expand Down
24 changes: 16 additions & 8 deletions src/RulesEngine/Models/RuleParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,41 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;
using System.Runtime.InteropServices.ComTypes;

namespace RulesEngine.Models
{
[ExcludeFromCodeCoverage]
public class RuleParameter
{
public RuleParameter(string name, object value) : this(name, value?.GetType(), value) { }
protected RuleParameter(string name, Type type, object value = null)
public RuleParameter(string name, object value)
{
Name = name;
Value = Utils.GetTypedObject(value);
Type = type ?? typeof(object);
ParameterExpression = Expression.Parameter(Type, Name);
Init(name, Value?.GetType());
}

internal RuleParameter(string name, Type type, object value = null)
{
Value = Utils.GetTypedObject(value);
Init(name, type);
}

public Type Type { get; private set; }
public string Name { get; private set; }
public object Value { get; private set; }
public ParameterExpression ParameterExpression { get; private set; }

private void Init(string name, Type type)
{
Name = name;
Type = type ?? typeof(object);
ParameterExpression = Expression.Parameter(Type, Name);
}

public static RuleParameter Create<T>(string name, T value)
{
var typedValue = Utils.GetTypedObject(value);
var type = typedValue?.GetType() ?? typeof(T);

return new RuleParameter(name,type,value);
return new RuleParameter(name, type, value);
}
}
}

0 comments on commit 04c51f5

Please sign in to comment.