本文整理汇总了C#中EvaluationContext.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# EvaluationContext.GetValue方法的具体用法?C# EvaluationContext.GetValue怎么用?C# EvaluationContext.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EvaluationContext
的用法示例。
在下文中一共展示了EvaluationContext.GetValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SimplePOCO
public void SimplePOCO()
{
EvaluationContext context = new EvaluationContext(new Dictionary<string, object>() {
{"customer", new Customer(){ Age=12, Name="Customer1"}}
}, null);
Assert.AreEqual("Customer1", context.GetValue("customer.Name").ToString());
Assert.AreEqual(12, (int)context.GetValue("customer.Age"));
}
示例2: Evaluate
public override void Evaluate(EvaluationContext evaluationContext, Action<string> write)
{
string reference = this.Arguments;
object evaluationResult = evaluationContext.GetValue(reference);
write( evaluationResult == null ? string.Empty : evaluationResult.ToString() );
}
示例3: ListCount
public void ListCount()
{
EvaluationContext context = new EvaluationContext(new Dictionary<string, object>() {
{"integerlist", new List<int>(){1, 2}}
}, null);
Assert.AreEqual(2, (int)context.GetValue("integerlist.Count"));
}
示例4: Dictionary
public void Dictionary()
{
EvaluationContext context = new EvaluationContext(new Dictionary<string, object>() {
{"customer", new Dictionary<string, string>(){ {"Name", "Customer1"}}}
}, null);
Assert.AreEqual("Customer1", context.GetValue("customer.Name").ToString());
}
示例5: SimplePOCOs
public void SimplePOCOs()
{
EvaluationContext context = new EvaluationContext(new Dictionary<string, object>() {
{
"customer",
new Customer()
{
Age=12,
Name="Customer1",
Friend = new Customer()
{
Name= "Friend",
Friend = new Customer()
{
Name = "Subfriend"
}
}
}
}
}, null);
Assert.AreEqual("Subfriend", context.GetValue("customer.Friend.Friend.Name").ToString());
}
示例6: Evaluate
public override void Evaluate(EvaluationContext evaluationContext, Action<string> write)
{
Match match = Regex.Match(this.Arguments, @"\$\{(?'var'[a-zA-Z0-9.]+)\}(?:\s+)in(?:\s+)\$\{(?'source'[a-zA-Z0-9.]+)\}");
if (!match.Success)
throw new EvaluationException("Could not interpret foreach: " + this.Arguments);
string varToIntroduce = match.Groups["var"].Value;
string sourceName = match.Groups["source"].Value;
object source = evaluationContext.GetValue(sourceName);
IEnumerable loopable = source as IEnumerable;
if (loopable == null)
throw new EvaluationException(sourceName + " is not able to be foreached");
ITemplate noDataTemplate = null;
ITemplate beforeAllTemplate = null;
ITemplate beforeTemplate = null;
ITemplate oddTemplate = null;
ITemplate evenTemplate = null;
ITemplate afterTemplate = null;
ITemplate betweenTemplate = null;
ITemplate afterAllTemplate = null;
ITemplate eachTemplate = null;
//TODO?: All inner sections are optional, and they can appear in any order multiple times (sections with same name will have their content appended)
ITemplate lastSubTemplateChild = null;
foreach (ITemplate child in this.Children.ToList())
{
ForeachSubTemplate subTemplate = child as ForeachSubTemplate;
if (subTemplate != null)
{
switch (subTemplate.UsedTag)
{
case "beforeall":
beforeAllTemplate = subTemplate;
break;
case "before":
beforeTemplate = subTemplate;
break;
case "odd":
oddTemplate = subTemplate;
break;
case "even":
evenTemplate = subTemplate;
break;
case "each":
eachTemplate = subTemplate;
break;
case "after":
afterTemplate = subTemplate;
break;
case "between":
betweenTemplate = subTemplate;
break;
case "afterall":
afterAllTemplate = subTemplate;
break;
case "nodata":
noDataTemplate = subTemplate;
break;
}
lastSubTemplateChild = subTemplate;
}
else
{
if (lastSubTemplateChild != null)
{
lastSubTemplateChild.Children.Add(child);
this.Children.Remove(child);
}
}
}
bool isEven = true;
bool hadData = false;
bool isFirst = true;
long index = 0;
foreach (object item in loopable)
{
index++;
hadData = true;
isEven = !isEven;
EvaluationContext subEvaluationContext = new EvaluationContext(
new Dictionary<string, object>() {
{varToIntroduce, item}
},
evaluationContext
);
if (isFirst && beforeAllTemplate != null)
{
beforeAllTemplate.Evaluate(evaluationContext, write);
}
if (beforeTemplate != null)
//.........这里部分代码省略.........