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


C# CodeContext.Add方法代码示例

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


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

示例1: TestSimpleNestedReplacement

        public void TestSimpleNestedReplacement()
        {
            var cc = new CodeContext();
            cc.Add("d", Expression.Variable(typeof(int), "f"));
            cc.Add("f", Expression.Constant(20));

            var expr = ParameterReplacementExpressionVisitor.ReplaceParameters(Expression.Variable(typeof(int), "d"), cc);

            var asconst = expr as ConstantExpression;
            Assert.IsNotNull(asconst, "constant replacement");
            Assert.AreEqual(20, asconst.Value, "value of translation");
        }
开发者ID:gordonwatts,项目名称:LINQtoROOT,代码行数:12,代码来源:ParameterReplacementExpressionVisitorTest.cs

示例2: TestBadTypeReplacement

        public void TestBadTypeReplacement()
        {
            var cc = new CodeContext();
            cc.Add("d", Expression.Variable(typeof(int), "f"));
            cc.Add("f", Expression.Constant(20.0));

            var expr = ParameterReplacementExpressionVisitor.ReplaceParameters(Expression.Variable(typeof(int), "d"), cc);
        }
开发者ID:gordonwatts,项目名称:LINQtoROOT,代码行数:8,代码来源:ParameterReplacementExpressionVisitorTest.cs

示例3: TestDeclarableParameterReplacement

        public void TestDeclarableParameterReplacement()
        {
            var e1 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var e2 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));

            var cc = new CodeContext();
            cc.Add(e1.ParameterName, e2);

            var expr = ParameterReplacementExpressionVisitor.ReplaceParameters(e1, cc);

            Assert.AreEqual(e2, expr, "value of translation");
        }
开发者ID:gordonwatts,项目名称:LINQtoROOT,代码行数:12,代码来源:ParameterReplacementExpressionVisitorTest.cs

示例4: TestArrayReplacement

        public void TestArrayReplacement()
        {
            var myvar = Expression.Variable(typeof(int[]), "d");
            var myref = Expression.ArrayIndex(myvar, Expression.Constant(1));

            var cc = new CodeContext();
            cc.Add("d", Expression.Variable(typeof(int[]), "dude"));

            var expr = ParameterReplacementExpressionVisitor.ReplaceParameters(myref, cc);

            var be = expr as BinaryExpression;
            Assert.AreEqual(ExpressionType.ArrayIndex, be.NodeType, "index bad");
            var pe = be.Left as ParameterExpression;
            Assert.IsNotNull(pe, "bad array value");
            Assert.AreEqual("dude", pe.Name, "array parameter name");
        }
开发者ID:gordonwatts,项目名称:LINQtoROOT,代码行数:16,代码来源:ParameterReplacementExpressionVisitorTest.cs

示例5: TestLambdaWithPredefinedNameAsParam

        public void TestLambdaWithPredefinedNameAsParam()
        {
            /// This is basically a scope test! :-)
            Expression<Func<testLambdaSimple, float>> lambdaExpr = t => t.pt / ((float)100.0);

            CodeContext cc = new CodeContext();
            cc.Add("t", Expression.Parameter(typeof(testLambdaSimple), "fook"));
            var expr = ParameterReplacementExpressionVisitor.ReplaceParameters(lambdaExpr, cc);

            Assert.AreEqual(lambdaExpr.ToString(), expr.ToString(), "lambda changed");
            Assert.AreEqual("fook", (cc.GetReplacement("t") as ParameterExpression).Name, "code context was altered");
        }
开发者ID:gordonwatts,项目名称:LINQtoROOT,代码行数:12,代码来源:ParameterReplacementExpressionVisitorTest.cs

示例6: TestSubqueryNestedPatternReplacement

        public void TestSubqueryNestedPatternReplacement()
        {
            var qexpr = new QuerySourceReferenceExpression(new dummyQuerySource());

            CodeContext cc = new CodeContext();
            cc.Add("d", Expression.Variable(typeof(int), "f"));
            cc.Add("f", Expression.Variable(typeof(int), "fork"));
            cc.Add(qexpr.ReferencedQuerySource, Expression.Parameter(typeof(int), "d"));

            var expr = ParameterReplacementExpressionVisitor.ReplaceParameters(qexpr, cc);

            var asp = expr as ParameterExpression;
            Assert.IsNotNull(asp, "expected the returned expression to be of type ParameterExpression");
            Assert.AreEqual(typeof(int), asp.Type, "bad type coming back");
            Assert.AreEqual("fork", asp.Name, "variable name");
        }
开发者ID:gordonwatts,项目名称:LINQtoROOT,代码行数:16,代码来源:ParameterReplacementExpressionVisitorTest.cs

示例7: TestArrayIndexReplacement

        public void TestArrayIndexReplacement()
        {
            var myarray = Expression.Variable(typeof(int[]), "darray");
            var myindex = Expression.Variable(typeof(int), "d");
            var myref = Expression.ArrayIndex(myarray, myindex);

            var cc = new CodeContext();
            cc.Add("d", Expression.Constant(10));

            var expr = ParameterReplacementExpressionVisitor.ReplaceParameters(myref, cc);

            var be = expr as BinaryExpression;
            Assert.AreEqual(ExpressionType.ArrayIndex, be.NodeType, "index bad");
            var ce = be.Right as ConstantExpression;
            Assert.IsNotNull(ce, "reference to constant failed");
            Assert.AreEqual(10, ce.Value, "value of array index");
        }
开发者ID:gordonwatts,项目名称:LINQtoROOT,代码行数:17,代码来源:ParameterReplacementExpressionVisitorTest.cs

示例8: TestReplacementInfiniate

        public void TestReplacementInfiniate()
        {
            CodeContext cc = new CodeContext();
            cc.Add("expr2", Expression.Parameter(typeof(int), "expr1"));
            cc.Add("expr1", Expression.Parameter(typeof(int), "expr2"));

            Assert.AreEqual("expr1", (new ValSimple("expr1", typeof(int))).PerformAllSubstitutions(cc).RawValue, "no translation expected");
        }
开发者ID:gordonwatts,项目名称:LINQtoROOT,代码行数:8,代码来源:VarUtilsTest.cs


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