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


C# ExecutionContext.GetVariable方法代码示例

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


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

示例1: Execute

        public override string Execute(ExecutionContext context)
        {
            string varName = VariableName.ToString();

            context.SetLocalVariable(varName, context.IsVariableSet(varName) ? context.GetVariable(varName) : null);

            return "";
        }
开发者ID:peppy,项目名称:osq2osb,代码行数:8,代码来源:LocalNode.cs

示例2: TestFormat

        public void TestFormat()
        {
            var context = new ExecutionContext();

            var formatFunc = (ExecutionContext.OsqFunction)context.GetVariable("format");

            var ret = formatFunc(new TokenNode(null, new[] {
                new TokenNode(new Token(TokenType.Symbol, ","), new[] {
                    new TokenNode(new Token(TokenType.String, "this is a {0} {1:D9}")),
                    new TokenNode(new Token(TokenType.String, "test")),
                    new TokenNode(new Token(TokenType.Number, 10)),
                })
            }), context);

            Assert.AreEqual("this is a test 000000010", ret);
        }
开发者ID:strager,项目名称:osq2osb,代码行数:16,代码来源:ExecutionContextTests.cs

示例3: Evaluate

        public object Evaluate(ExecutionContext context)
        {
            switch(Token.TokenType) {
                default:
                case TokenType.Number:
                case TokenType.String:
                    return Token.Value;

                case TokenType.Identifier:
                case TokenType.Symbol:
                    object item = context.GetVariable(Token.Value.ToString());

                    var asFunc = item as ExecutionContext.OsqFunction;

                    return asFunc == null ? item : asFunc.Invoke(this, context);
            }
        }
开发者ID:peppy,项目名称:osq2osb,代码行数:17,代码来源:TokenNode.cs

示例4: Execute

        public override string Execute(ExecutionContext context)
        {
            var output = new StringBuilder();

            double counter = Convert.ToDouble(Start.Evaluate(context), Parser.DefaultCulture);

            while(true) {
                context.SetVariable(Variable, counter);

                output.Append(ExecuteChildren(context));

                counter = Convert.ToDouble(context.GetVariable(Variable), Parser.DefaultCulture);
                counter += Step == null ? 1.0 : Convert.ToDouble(Step.Evaluate(context), Parser.DefaultCulture);

                if(counter >= Convert.ToDouble(End.Evaluate(context), Parser.DefaultCulture)) {
                    break;
                }
            }

            return output.ToString();
        }
开发者ID:peppy,项目名称:osq2osb,代码行数:21,代码来源:ForNode.cs

示例5: TestMin

        public void TestMin()
        {
            var context = new ExecutionContext();

            var formatFunc = (ExecutionContext.OsqFunction)context.GetVariable("min");

            var ret = formatFunc(new TokenNode(null, new[] {
                new TokenNode(new Token(TokenType.Symbol, ","), new[] {
                    new TokenNode(new Token(TokenType.Number, 10)),
                    new TokenNode(new Token(TokenType.Number, 100)),
                })
            }), context);

            Assert.AreEqual(10, ret);
        }
开发者ID:strager,项目名称:osq2osb,代码行数:15,代码来源:ExecutionContextTests.cs

示例6: TestInt

        public void TestInt()
        {
            var context = new ExecutionContext();

            var formatFunc = (ExecutionContext.OsqFunction)context.GetVariable("int");

            var ret = formatFunc(new TokenNode(null, new[] {
                new TokenNode(new Token(TokenType.Number, 13.37)),
            }), context);

            Assert.AreEqual(13, ret);
        }
开发者ID:strager,项目名称:osq2osb,代码行数:12,代码来源:ExecutionContextTests.cs


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