本文整理汇总了C#中ExpressionContext类的典型用法代码示例。如果您正苦于以下问题:C# ExpressionContext类的具体用法?C# ExpressionContext怎么用?C# ExpressionContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExpressionContext类属于命名空间,在下文中一共展示了ExpressionContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExpressionTokenizer
/**
* <summary>Creates a new tokenizer for the specified input
* stream.</summary>
*
* <param name='input'>the input stream to read</param>
* <param name='expressionContext'>the expression context to work on</param>
*
* <exception cref='ParserCreationException'>if the tokenizer
* couldn't be initialized correctly</exception>
*/
public ExpressionTokenizer(TextReader input, ExpressionContext expressionContext)
: base(input, true)
{
_expressionContext = expressionContext;
CreatePatterns();
}
示例2: TestExpressionClone
public void TestExpressionClone()
{
ExpressionContext context = new ExpressionContext();
context.Variables.Add("a", 100);
context.Variables.Add("b", 200);
IGenericExpression<int> exp1 = this.CreateGenericExpression<int>("(a * b)", context);
IGenericExpression<int> exp2 = exp1.Clone() as IGenericExpression<int>;
Assert.AreNotSame(exp1.Context.Variables, exp2.Context.Variables);
exp2.Context.Variables["a"] = 10;
exp2.Context.Variables["b"] = 20;
Assert.AreEqual(10 * 20, exp2.Evaluate());
Thread t1 = new Thread(ThreadRunClone);
Thread t2 = new Thread(ThreadRunClone);
t1.Start(exp1);
t2.Start(exp2);
IDynamicExpression exp3 = this.CreateDynamicExpression("a * b", context);
IDynamicExpression exp4 = exp3.Clone() as IDynamicExpression;
Assert.AreEqual(100 * 200, exp4.Evaluate());
}
示例3: RankedArrayIndexOnOwner
public void RankedArrayIndexOnOwner()
{
var context = new ExpressionContext(null, new Owner());
Resolve(context, "RankedProperty[0,0]", 1);
Resolve(context, "RankedProperty[1,1]", 4);
}
示例4: GetExpressionContext
private static ExpressionContext GetExpressionContext()
{
var expressionOwner = new TestData { Id = "World" };
var context = new ExpressionContext(expressionOwner);
context.Imports.AddType(typeof(TestDataExtensions));
return context;
}
示例5: TestBatchLoad
public void TestBatchLoad()
{
// Test that we can add expressions in any order
CalculationEngine engine = new CalculationEngine();
ExpressionContext context = new ExpressionContext();
int interest = 2;
context.Variables.Add("interest", interest);
BatchLoader loader = engine.CreateBatchLoader();
loader.Add("c", "a + b", context);
loader.Add("a", "100 + interest", context);
loader.Add("b", "a + 1 + a", context);
// Test an expression with a reference in a string
loader.Add("d", "\"str \\\" str\" + a + \"b\"", context);
engine.BatchLoad(loader);
int result = engine.GetResult<int>("b");
Assert.AreEqual((100 + interest) + 1 + (100 + interest), result);
interest = 300;
context.Variables["interest"] = interest;
engine.Recalculate("a");
result = engine.GetResult<int>("b");
Assert.AreEqual((100 + interest) + 1 + (100 + interest), result);
result = engine.GetResult<int>("c");
Assert.AreEqual((100 + interest) + 1 + (100 + interest) + (100 + interest), result);
Assert.AreEqual("str \" str400b", engine.GetResult<string>("d"));
}
示例6: ExpressionOptions
internal ExpressionOptions(ExpressionContext owner)
{
MyOwner = owner;
MyProperties = new PropertyDictionary();
this.InitializeProperties();
}
示例7: DynamicCalculator
/// <summary>
/// Creates a new instance of the <see cref="DynamicCalculator"/>.
/// </summary>
public DynamicCalculator()
{
m_variableNames = new HashSet<string>();
m_keyMapping = new Dictionary<MeasurementKey, string>();
m_nonAliasedTokens = new SortedDictionary<int, string>();
m_expressionContext = new ExpressionContext();
}
示例8: processGlobal
private string processGlobal(string expr)
{
var val = PluginMain.debugManager.FlashInterface.Session.getGlobal(expr);
//var val = PluginMain.debugManager.FlashInterface.Session.getValue(Convert.ToInt64(expr));
var ctx = new ExpressionContext(PluginMain.debugManager.FlashInterface.Session, PluginMain.debugManager.FlashInterface.GetFrames()[PluginMain.debugManager.CurrentFrame]);
return ctx.FormatValue(val);
}
示例9: TestExpressionVariables
public void TestExpressionVariables()
{
ExpressionContext context1 = new ExpressionContext();
context1.Imports.Add(new Import(typeof(Math)));
var exp1 = new DynamicExpression("sin(pi)", ExpressionLanguage.Flee);
var boundExp1 = exp1.Bind(context1);
ExpressionContext context2 = new ExpressionContext();
context2.Imports.Add(new Import(typeof(Math)));
var exp2 = new DynamicExpression<double>("cos(pi/2)", ExpressionLanguage.Flee);
var boundExp2 = exp2.Bind(context2);
ExpressionContext context3 = new ExpressionContext();
context3.Variables.Add("a", boundExp1);
context3.Variables.Add("b", boundExp2);
var exp3 = new DynamicExpression("cast(a, double) + b", ExpressionLanguage.Flee);
double a = Math.Sin(Math.PI);
double b = Math.Cos(Math.PI / 2);
Assert.AreEqual(a + b, exp3.Invoke(context3));
ExpressionContext context4 = new ExpressionContext();
context4.Variables.Add("a", boundExp1);
context4.Variables.Add("b", boundExp2);
var exp4 = new DynamicExpression<double>("(cast(a, double) * b) + (b - cast(a, double))", ExpressionLanguage.Flee);
Assert.AreEqual((a * b) + (b - a), exp4.Invoke(context4));
}
示例10: BuildExpression
/*
private void BuildExpression()
{
foreach (Assignment assignment in _assignments)
{
string stringDelim = "\"";
if (assignment.Variable.VariableDataType != VariableDataType.String)
stringDelim = string.Empty;
_expression += assignment.Variable.Mnemonic + " = " + stringDelim + assignment.AssignmentExpression + stringDelim + ";";
}
}
*/
private void Parse(ExpressionContext context, CalculationMemory calculationMemory)
{
_assignments.Clear();
// assignments seprator token
string[] temp = _expression.Split(';');
int idx = 0;
//temp.OrderBy?
foreach (string assignmentExpression in temp)
{
if (assignmentExpression != string.Empty)
{
// assignment token
string[] temp2 = assignmentExpression.Split('=');
if (temp2.Length != 2)
throw new InequationEngineException(ExceptionType.NumberOfAssigmentTokens);
string variableName = temp2[0].ToLower().Trim();
Variable variable = calculationMemory[variableName];
if (variable == null)
throw new InequationEngineException(ExceptionType.VariableNotFoundInCalcMemory);
Assignment assignment = new Assignment(variable, temp2[1]);
_assignments.Add(idx, assignment);
idx++;
}
}
}
示例11: TestFastVariables
public void TestFastVariables()
{
// Test should take 200ms or less
const int EXPECTED_TIME = 200;
const int ITERATIONS = 100000;
ExpressionContext context = new ExpressionContext();
VariableCollection vars = context.Variables;
vars.DefineVariable("a", typeof(Int32));
vars.DefineVariable("b", typeof(Int32));
IDynamicExpression e = this.CreateDynamicExpression("a + b * (a ^ 2)", context);
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i <= ITERATIONS - 1; i++) {
object result = e.Evaluate();
vars["a"] = 200;
vars["b"] = 300;
}
sw.Stop();
this.PrintSpeedMessage("Fast variables", ITERATIONS, sw);
NUnit.Framework.Assert.Less((decimal)sw.ElapsedMilliseconds, EXPECTED_TIME, "Test time above expected value");
}
示例12: ToElementInit
internal ElementInit ToElementInit(ExpressionContext context)
{
return
Expression.ElementInit(
this.AddMethod.ToMemberInfo(context),
(this.Arguments ?? new ExpressionNodeList()).GetExpressions(context));
}
示例13: Compile
public void Compile(ExpressionContext context)
{
// TODO: verify wheather the expression is a value (no need to compile)
bool isValue = false;
if (!isValue)
eDynamic = context.CompileDynamic(AssignmentExpression);
}
示例14: PMNameNode
public PMNameNode(ExpressionNode node, string tokenString, ExpressionContext context)
: base(node, tokenString, context)
{
string[] parts = Name.Split('.');
if (parts.Length == 3)
{
isAttribute = true;
ObjectName = (PMObjectType)Enum.Parse(typeof(PMObjectType), parts[0], true);
FieldName = parts[2].Trim('[',']').Trim();
}
else if (parts.Length == 2)
{
ObjectName = (PMObjectType)Enum.Parse(typeof(PMObjectType), parts[0], true);
if (parts[1].Trim().EndsWith("_Attributes"))
{
isAttribute = true;
FieldName = parts[1].Substring(0, parts[1].Length - 11);
}
else
FieldName = parts[1];
}
else
{
ObjectName = PMObjectType.PMTran;
FieldName = Name;
}
}
示例15: InequationEngine
public InequationEngine()
{
_context = new ExpressionContext();
_context.Imports.AddType(typeof(CustomFunctions));
_context.Options.EmitToAssembly = false;
_calculationMemory = new CalculationMemory(_context);
}