当前位置: 首页>>代码示例>>C#>>正文


C# EvaluationContext.GetValue方法代码示例

本文整理汇总了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"));
        }
开发者ID:spdr870,项目名称:LemurLang,代码行数:9,代码来源:EvaluationContextTest.cs

示例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() );
        }
开发者ID:spdr870,项目名称:LemurLang,代码行数:7,代码来源:PrintTemplate.cs

示例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"));
        }
开发者ID:spdr870,项目名称:LemurLang,代码行数:8,代码来源:EvaluationContextTest.cs

示例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());
        }
开发者ID:spdr870,项目名称:LemurLang,代码行数:8,代码来源:EvaluationContextTest.cs

示例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());
        }
开发者ID:spdr870,项目名称:LemurLang,代码行数:23,代码来源:EvaluationContextTest.cs

示例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)
//.........这里部分代码省略.........
开发者ID:spdr870,项目名称:LemurLang,代码行数:101,代码来源:ForeachTemplate.cs


注:本文中的EvaluationContext.GetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。