本文整理汇总了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");
}
示例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);
}
示例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");
}
示例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");
}
示例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");
}
示例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");
}
示例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");
}
示例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");
}