-
Notifications
You must be signed in to change notification settings - Fork 585
/
Copy pathRuleParameter.cs
53 lines (43 loc) · 1.46 KB
/
RuleParameter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using RulesEngine.HelperFunctions;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;
namespace RulesEngine.Models
{
[ExcludeFromCodeCoverage]
public class RuleParameter
{
public RuleParameter(string name, object value)
{
Value = Utils.GetTypedObject(value);
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(string name, Type type)
{
return new RuleParameter(name, type);
}
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);
}
}
}