Skip to content

Commit fd126c2

Browse files
author
Sébastien Geiser
committed
start context object implementation
1 parent 4cb3e9d commit fd126c2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,11 @@ public BindingFlags StaticBindingFlag
816816

817817
#region Custom and on the fly variables and methods
818818

819+
/// <summary>
820+
/// If set, this object is used to use it's properties and methods as global variables and functions
821+
/// </summary>
822+
public object Context { get; set; }
823+
819824
private IDictionary<string, object> variables = new Dictionary<string, object>(StringComparer.Ordinal);
820825

821826
/// <summary>
@@ -876,6 +881,26 @@ public ExpressionEvaluator(IDictionary<string, object> variables) : this()
876881
Variables = variables;
877882
}
878883

884+
/// <summary>
885+
/// Constructor with context initialize
886+
/// </summary>
887+
/// <param name="context">the context that propose it's methods and properties to the evaluation</param>
888+
public ExpressionEvaluator(object context) : this()
889+
{
890+
Context = context;
891+
}
892+
893+
/// <summary>
894+
/// Constructor with variables and context initialize
895+
/// </summary>
896+
/// <param name="context">the context that propose it's methods and properties to the evaluation</param>
897+
/// <param name="variables">The Values of variables use in the expressions</param>
898+
public ExpressionEvaluator(object context, IDictionary<string, object> variables) : this()
899+
{
900+
Context = context;
901+
Variables = variables;
902+
}
903+
879904
protected virtual void DefaultDecimalSeparatorInit()
880905
{
881906
numberRegexPattern = string.Format(numberRegexOrigPattern, @"\.", string.Empty);

0 commit comments

Comments
 (0)