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


C# CodeContext.SetLoopVariable方法代码示例

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


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

示例1: ProcessResultOperator

        /// <summary>Test stub for ProcessResultOperator(ResultOperatorBase, QueryModel, IGeneratedCode)</summary>
        internal GeneratedCode ProcessResultOperator(
            ROTakeSkipOperators target,
            ResultOperatorBase resultOperator,
            QueryModel queryModel,
            GeneratedCode codeEnv
        )
        {
            if (codeEnv.ResultValue != null)
                throw new ArgumentException("this should not be null for this test");
            if (codeEnv.CodeBody.DeclaredVariables == null)
                throw new ArgumentException("Need this declare variables to be defined");

            ///
            /// We always expect to be inside a loop - and depend on it for doing our declares, so add something...
            /// 

            var inlineBlock = new StatementInlineBlock();
            codeEnv.Add(inlineBlock);

            ///
            /// Get the environment setup and run it
            /// 

            CodeContext c = new CodeContext();
            c.SetLoopVariable(Expression.Variable(typeof(int), "d"), null);

            target.ProcessResultOperator(resultOperator, queryModel, codeEnv, c, MEFUtilities.MEFContainer);

            codeEnv.DumpCodeToConsole();

            ///
            /// First, there should be a counter now declared and ready to go in the current variable block - which will
            /// be the outer one for this test. If this is the outter most, then this is going to be burried.
            /// 

            var declBlock = inlineBlock.Parent.Parent as IBookingStatementBlock;
            Assert.IsNotNull(declBlock, "Expecting a declaration block above!");

            Assert.AreEqual(1, inlineBlock.Statements.Count(), "Expected an if block/increment!");
            Assert.IsInstanceOfType(inlineBlock.Statements.First(), typeof(StatementIfOnCount), "if statement not found!");

            var s = inlineBlock.Statements.First() as StatementIfOnCount;

            bool isTopLevel = codeEnv.DumpCode().Where(l => l.Contains("static int")).Any();
            if (!isTopLevel)
            {
                Assert.AreEqual(1, declBlock.DeclaredVariables.Count(), "Expected only 1 variable to be declared");
                Assert.IsInstanceOfType(declBlock.DeclaredVariables.First(), typeof(DeclarableParameter), "Expected it to be a counter");
            } else
            {
                Assert.AreEqual(1, (s.Parent as IBookingStatementBlock).DeclaredVariables.Count());
            }

            string count = "";
            if (resultOperator is SkipResultOperator)
            {
                count = (resultOperator as SkipResultOperator).Count.ToString();
            }
            else if (resultOperator is TakeResultOperator)
            {
                count = (resultOperator as TakeResultOperator).Count.ToString();
            }
            Assert.AreEqual(count, s.Limit.RawValue, "bad count made it through");

            ///
            /// Finally, the current loop variable should be identical, and there should be no result set.
            /// 

            Assert.IsNull(codeEnv.ResultValue, "result value");
            Assert.IsInstanceOfType(c.LoopVariable, typeof(ParameterExpression), "loop variable type");
            var lv = c.LoopVariable as ParameterExpression;
            Assert.AreEqual("d", lv.Name, "loop variable name");

            //
            // Dump everything and return. To force it out, add a dummy statement
            // (because if statements, etc., are smart enough to not print anything if they
            // are empty).
            //

            codeEnv.Add(new StatementSimpleStatement("fork = left"));
            codeEnv.DumpCodeToConsole();

            return codeEnv;
        }
开发者ID:gordonwatts,项目名称:LINQtoROOT,代码行数:85,代码来源:TakeSkipOperatorsTest.cs


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