• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# ExpressionContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ExpressionContext的典型用法代码示例。如果您正苦于以下问题:C# ExpressionContext类的具体用法?C# ExpressionContext怎么用?C# ExpressionContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ExpressionContext类属于命名空间,在下文中一共展示了ExpressionContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ExpressionTokenizer

    /**
     * <summary>Creates a new tokenizer for the specified input
     * stream.</summary>
     *
     * <param name='input'>the input stream to read</param>
     * <param name='expressionContext'>the expression context to work on</param>
     *
     * <exception cref='ParserCreationException'>if the tokenizer
     * couldn't be initialized correctly</exception>
     */
    public ExpressionTokenizer(TextReader input, ExpressionContext expressionContext)
        : base(input, true)
    {

        _expressionContext = expressionContext;
        CreatePatterns();
    }
开发者ID:netgrim,项目名称:FleeSharp,代码行数:17,代码来源:ExpressionTokenizer.cs


示例2: TestExpressionClone

        public void TestExpressionClone()
        {
            ExpressionContext context = new ExpressionContext();
            context.Variables.Add("a", 100);
            context.Variables.Add("b", 200);
            IGenericExpression<int> exp1 = this.CreateGenericExpression<int>("(a * b)", context);

            IGenericExpression<int> exp2 = exp1.Clone() as IGenericExpression<int>;

            Assert.AreNotSame(exp1.Context.Variables, exp2.Context.Variables);

            exp2.Context.Variables["a"] = 10;
            exp2.Context.Variables["b"] = 20;

            Assert.AreEqual(10 * 20, exp2.Evaluate());

            Thread t1 = new Thread(ThreadRunClone);
            Thread t2 = new Thread(ThreadRunClone);
            t1.Start(exp1);
            t2.Start(exp2);

            IDynamicExpression exp3 = this.CreateDynamicExpression("a * b", context);
            IDynamicExpression exp4 = exp3.Clone() as IDynamicExpression;

            Assert.AreEqual(100 * 200, exp4.Evaluate());
        }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:26,代码来源:IndividualTests.cs


示例3: RankedArrayIndexOnOwner

        public void RankedArrayIndexOnOwner()
        {
            var context = new ExpressionContext(null, new Owner());

            Resolve(context, "RankedProperty[0,0]", 1);
            Resolve(context, "RankedProperty[1,1]", 4);
        }
开发者ID:parsnips,项目名称:Expressions,代码行数:7,代码来源:Indexing.cs


示例4: GetExpressionContext

 private static ExpressionContext GetExpressionContext()
 {
     var expressionOwner = new TestData { Id = "World" };
     var context = new ExpressionContext(expressionOwner);
     context.Imports.AddType(typeof(TestDataExtensions));
     return context;
 }
开发者ID:ThomasZitzler,项目名称:flee,代码行数:7,代码来源:ExtensionMethodTest.cs


示例5: TestBatchLoad

        public void TestBatchLoad()
        {
            // Test that we can add expressions in any order
            CalculationEngine engine = new CalculationEngine();
            ExpressionContext context = new ExpressionContext();

            int interest = 2;
            context.Variables.Add("interest", interest);

            BatchLoader loader = engine.CreateBatchLoader();

            loader.Add("c", "a + b", context);
            loader.Add("a", "100 + interest", context);
            loader.Add("b", "a + 1 + a", context);
            // Test an expression with a reference in a string
            loader.Add("d", "\"str \\\" str\" + a + \"b\"", context);

            engine.BatchLoad(loader);

            int result = engine.GetResult<int>("b");
            Assert.AreEqual((100 + interest) + 1 + (100 + interest), result);

            interest = 300;
            context.Variables["interest"] = interest;
            engine.Recalculate("a");

            result = engine.GetResult<int>("b");
            Assert.AreEqual((100 + interest) + 1 + (100 + interest), result);

            result = engine.GetResult<int>("c");
            Assert.AreEqual((100 + interest) + 1 + (100 + interest) + (100 + interest), result);

            Assert.AreEqual("str \" str400b", engine.GetResult<string>("d"));
        }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:34,代码来源:CalcEngineTestFixture.cs


示例6: ExpressionOptions

		internal ExpressionOptions(ExpressionContext owner)
		{
			MyOwner = owner;
			MyProperties = new PropertyDictionary();

			this.InitializeProperties();
		}
开发者ID:netgrim,项目名称:FleeSharp,代码行数:7,代码来源:ExpressionOptions.cs


示例7: DynamicCalculator

 /// <summary>
 /// Creates a new instance of the <see cref="DynamicCalculator"/>.
 /// </summary>
 public DynamicCalculator()
 {
     m_variableNames = new HashSet<string>();
     m_keyMapping = new Dictionary<MeasurementKey, string>();
     m_nonAliasedTokens = new SortedDictionary<int, string>();
     m_expressionContext = new ExpressionContext();
 }
开发者ID:avs009,项目名称:gsf,代码行数:10,代码来源:DynamicCalculator.cs


示例8: processGlobal

 private string processGlobal(string expr)
 {
     var val = PluginMain.debugManager.FlashInterface.Session.getGlobal(expr);
     //var val = PluginMain.debugManager.FlashInterface.Session.getValue(Convert.ToInt64(expr));
     var ctx = new ExpressionContext(PluginMain.debugManager.FlashInterface.Session, PluginMain.debugManager.FlashInterface.GetFrames()[PluginMain.debugManager.CurrentFrame]);
     return ctx.FormatValue(val);
 }
开发者ID:xeronith,项目名称:flashdevelop,代码行数:7,代码来源:ImmediateUI.cs


示例9: TestExpressionVariables

        public void TestExpressionVariables()
        {
            ExpressionContext context1 = new ExpressionContext();
            context1.Imports.Add(new Import(typeof(Math)));
            var exp1 = new DynamicExpression("sin(pi)", ExpressionLanguage.Flee);
            var boundExp1 = exp1.Bind(context1);

            ExpressionContext context2 = new ExpressionContext();
            context2.Imports.Add(new Import(typeof(Math)));
            var exp2 = new DynamicExpression<double>("cos(pi/2)", ExpressionLanguage.Flee);
            var boundExp2 = exp2.Bind(context2);

            ExpressionContext context3 = new ExpressionContext();
            context3.Variables.Add("a", boundExp1);
            context3.Variables.Add("b", boundExp2);
            var exp3 = new DynamicExpression("cast(a, double) + b", ExpressionLanguage.Flee);

            double a = Math.Sin(Math.PI);
            double b = Math.Cos(Math.PI / 2);

            Assert.AreEqual(a + b, exp3.Invoke(context3));

            ExpressionContext context4 = new ExpressionContext();
            context4.Variables.Add("a", boundExp1);
            context4.Variables.Add("b", boundExp2);
            var exp4 = new DynamicExpression<double>("(cast(a, double) * b) + (b - cast(a, double))", ExpressionLanguage.Flee);

            Assert.AreEqual((a * b) + (b - a), exp4.Invoke(context4));
        }
开发者ID:parsnips,项目名称:Expressions,代码行数:29,代码来源:IndividualTests.cs


示例10: BuildExpression

        /*
        private void BuildExpression()
        {
            foreach (Assignment assignment in _assignments)
            {
                string stringDelim = "\"";
                if (assignment.Variable.VariableDataType != VariableDataType.String)
                    stringDelim = string.Empty;
                _expression += assignment.Variable.Mnemonic + " = " + stringDelim + assignment.AssignmentExpression + stringDelim + ";";
            }
        }
        */
        private void Parse(ExpressionContext context, CalculationMemory calculationMemory)
        {
            _assignments.Clear();
            // assignments seprator token
            string[] temp = _expression.Split(';');
            int idx = 0;

            //temp.OrderBy?
            foreach (string assignmentExpression in temp)
            {
                if (assignmentExpression != string.Empty)
                {
                    // assignment token
                    string[] temp2 = assignmentExpression.Split('=');
                    if (temp2.Length != 2)
                        throw new InequationEngineException(ExceptionType.NumberOfAssigmentTokens);

                    string variableName = temp2[0].ToLower().Trim();
                    Variable variable = calculationMemory[variableName];
                    if (variable == null)
                        throw new InequationEngineException(ExceptionType.VariableNotFoundInCalcMemory);

                    Assignment assignment = new Assignment(variable, temp2[1]);
                    _assignments.Add(idx, assignment);
                    idx++;
                }
            }
        }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:40,代码来源:ActionBlock.cs


示例11: TestFastVariables

        public void TestFastVariables()
        {
            // Test should take 200ms or less
            const int EXPECTED_TIME = 200;
            const int ITERATIONS = 100000;

            ExpressionContext context = new ExpressionContext();
            VariableCollection vars = context.Variables;
            vars.DefineVariable("a", typeof(Int32));
            vars.DefineVariable("b", typeof(Int32));
            IDynamicExpression e = this.CreateDynamicExpression("a + b * (a ^ 2)", context);

            Stopwatch sw = new Stopwatch();
            sw.Start();

            for (int i = 0; i <= ITERATIONS - 1; i++) {
                object result = e.Evaluate();
                vars["a"] = 200;
                vars["b"] = 300;
            }

            sw.Stop();

            this.PrintSpeedMessage("Fast variables", ITERATIONS, sw);
            NUnit.Framework.Assert.Less((decimal)sw.ElapsedMilliseconds, EXPECTED_TIME, "Test time above expected value");
        }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:26,代码来源:Benchmarks.cs


示例12: ToElementInit

 internal ElementInit ToElementInit(ExpressionContext context)
 {
     return 
         Expression.ElementInit(
             this.AddMethod.ToMemberInfo(context), 
             (this.Arguments ?? new ExpressionNodeList()).GetExpressions(context));
 }
开发者ID:zapov,项目名称:Serialize.Linq,代码行数:7,代码来源:ElementInitNode.cs


示例13: Compile

 public void Compile(ExpressionContext context)
 {
     // TODO: verify wheather the expression is a value (no need to compile)
     bool isValue = false;
     if (!isValue)
         eDynamic = context.CompileDynamic(AssignmentExpression);
 }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:7,代码来源:Assignment.cs


示例14: PMNameNode

		public PMNameNode(ExpressionNode node, string tokenString, ExpressionContext context)
			: base(node, tokenString, context)
		{
			string[] parts = Name.Split('.');

			if (parts.Length == 3)
			{
				isAttribute = true;
				ObjectName = (PMObjectType)Enum.Parse(typeof(PMObjectType), parts[0], true);
				FieldName = parts[2].Trim('[',']').Trim();
			}
			else if (parts.Length == 2)
			{
				ObjectName = (PMObjectType)Enum.Parse(typeof(PMObjectType), parts[0], true);
				if (parts[1].Trim().EndsWith("_Attributes"))
				{
					isAttribute = true;
					FieldName = parts[1].Substring(0, parts[1].Length - 11);
				}
				else
					FieldName = parts[1];
			}
			else
			{
				ObjectName = PMObjectType.PMTran;
				FieldName = Name;
			}
		}
开发者ID:PavelMPD,项目名称:SimpleProjects,代码行数:28,代码来源:PMExpressionParser.cs


示例15: InequationEngine

 public InequationEngine()
 {
     _context = new ExpressionContext();
     _context.Imports.AddType(typeof(CustomFunctions));
     _context.Options.EmitToAssembly = false;
     _calculationMemory = new CalculationMemory(_context);
 }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:7,代码来源:InequationEngine.cs


示例16: Resolve

		public void Resolve(IServiceProvider services)
		{
			MyServices = services;
            MyOptions = (ExpressionOptions)services.GetService(typeof(ExpressionOptions));
            MyContext = (ExpressionContext)services.GetService(typeof(ExpressionContext));
			this.ResolveInternal();
			this.Validate();
		}
开发者ID:netgrim,项目名称:FleeSharp,代码行数:8,代码来源:Member.cs


示例17: ExpressionParserOptions

		internal ExpressionParserOptions(ExpressionContext owner)
		{
			MyOwner = owner;
			MyProperties = new PropertyDictionary();
			MyParseCulture = CultureInfo.InvariantCulture;

			this.InitializeProperties();
		}
开发者ID:netgrim,项目名称:FleeSharp,代码行数:8,代码来源:ExpressionParserOptions.cs


示例18: Execute

 public void Execute(ExpressionContext context, CalculationMemory calculationMemory)
 {
     // Execute inequation and call action block
     if (Inequation.Execute(context))
         TrueActionBlock.Execute(context, calculationMemory);
     else
         FalseActionBlock.Execute(context, calculationMemory);
 }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:8,代码来源:Decision.cs


示例19: ObjectParamsWithMatchingArg

        public void ObjectParamsWithMatchingArg()
        {
            var context = new ExpressionContext(new[] { new Import("Owner", typeof(Owner)) });

            context.Variables.Add(new Variable("Variable") { Value = new[] { "hi" } });

            Resolve(context, "Owner.ObjectParams(0, Variable)", 2);
        }
开发者ID:parsnips,项目名称:Expressions,代码行数:8,代码来源:MethodCalls.cs


示例20: ComparingWithNull

        public void ComparingWithNull()
        {
            var context = new ExpressionContext();

            context.Variables.Add("Variable", new List<int>());

            Resolve(context, "Variable = null", false);
        }
开发者ID:parsnips,项目名称:Expressions,代码行数:8,代码来源:BinaryExpressions.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ExpressionGenerator类代码示例发布时间:2022-05-24
下一篇:
C# ExpressionBuilder类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap