當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。