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


C# Mono.Evaluate方法代码示例

本文整理汇总了C#中Mono.Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# Mono.Evaluate方法的具体用法?C# Mono.Evaluate怎么用?C# Mono.Evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mono的用法示例。


在下文中一共展示了Mono.Evaluate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetupVerifications

        private static List<Verification> SetupVerifications(Setup setup, EventStream stream, Mono.CSharp.Evaluator evaluator, string tab)
        {
            var verifications = new List<Verification>();

            // First set the verifications.
            foreach (var verifyList in setup.Verify)
            {
                var verifyBuilder = new StringBuilder(@"
            var func = new Func<IEventStream, IObservable<Unit>>(stream =>
            ");

                var filters = new List<string>();
                for (int i = 0; i < verifyList.Then.Count; i++)
                {
                    var var = ((char)(97 + i)).ToString(); // 97 == 'a'
                    var verify = verifyList.Then[i];
                    var topicType = setup.Topics.Find(verify.Topic);
                    Assert.True(topicType != TopicType.Unknown, "Undeclared topic '" + verify.Topic + "'");

                    var codeType = Brain.TopicCodeTypes.Find(topicType);

                    Assert.False((topicType == TopicType.Void && verify.Value != null),
                        string.Format("Cannot specify a value to compare for void topic '{0}' in verification '{1}'", verify.Topic, verify));

                    verifyBuilder.Append(tab).AppendLine("from {var} in stream.Commands<{type}>(\"{topic}\", \"{devices}\")".FormatWith(
                        new { var = var, type = codeType, topic = verify.Topic, devices = verify.Devices }));

                    // For void topics there's no need to filter out payload values,
                    // just getting a message with the given topic satisfies the query.
                    if (topicType != TopicType.Void)
                    {
                        // In this case we need to take into account the value
                        // received.
                        filters.Add("{var} == {value}".FormatWith(
                            new { var = var, value = FormatValue(topicType, verify.Value) }));
                    }
                }

                if (filters.Count > 0)
                {
                    verifyBuilder.Append(tab).Append("where ");
                    if (verifyList.Negate)
                    {
                        verifyBuilder
                            .Append("!(")
                            .Append(string.Join(" && ", filters))
                            .AppendLine(")");
                    }
                    else
                    {
                        verifyBuilder.AppendLine(string.Join(" && ", filters));
                    }
                }

                verifyBuilder
                    .Append(tab).AppendLine("select Unit.Default")
                    .AppendLine(");")
                    .AppendLine()
                    .Append("func;");

                Tracer.Get<BrainExercise>().Verbose("Buit verification query: " + verifyBuilder.ToString());

                var func = (Func<IEventStream, IObservable<Unit>>)evaluator.Evaluate(verifyBuilder.ToString());
                var query = func(stream);
                var verification = new Verification
                {
                    Expression = (verifyList.Negate ? "!" : "") +
                        string.Join(" and ", verifyList.Then.Select(t => t.ToString())),
                    Succeeded = verifyList.Negate,
                };

                if (verifyList.Negate)
                    query.Subscribe(_ => verification.Succeeded = false);
                else
                    query.Subscribe(_ => verification.Succeeded = true);

                verifications.Add(verification);
            }

            return verifications;
        }
开发者ID:kzu,项目名称:Sensorium,代码行数:81,代码来源:BrainExercise.cs


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