本文整理汇总了C#中System.Linq.Expressions.Expression.Reduce方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.Reduce方法的具体用法?C# Expression.Reduce怎么用?C# Expression.Reduce使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq.Expressions.Expression
的用法示例。
在下文中一共展示了Expression.Reduce方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompileExtensionExpression
private void CompileExtensionExpression(Expression expr) {
var instructionProvider = expr as IInstructionProvider;
if (instructionProvider != null) {
AddInstruction(instructionProvider.GetInstruction(this));
return;
}
var node = expr as Microsoft.Scripting.Ast.SymbolConstantExpression;
if (node != null) {
PushConstant(node.Value);
return;
}
if (expr.CanReduce) {
Compile(expr.Reduce());
} else {
throw new System.NotImplementedException();
}
}
示例2: CompileExtensionExpression
private void CompileExtensionExpression(Expression expr)
{
IInstructionProvider provider = expr as IInstructionProvider;
if (provider != null)
{
provider.AddInstructions(this);
}
else
{
if (!expr.CanReduce)
{
throw new NotImplementedException();
}
this.Compile(expr.Reduce());
}
}
示例3: Visit
public override Expression Visit(Expression node)
=> node != null
&& node.CanReduce
? Visit(node.Reduce())
: base.Visit(node);
示例4: CompileImpl
private object CompileImpl(Expression expression, CompilerState state)
{
if (state == null)
{
throw new ArgumentNullException("state");
}
state.RawReturnType = expression.Type;
while (expression.CanReduce)
{
expression = expression.Reduce();
}
LambdaExpression lambda;
var paramTypes = state.CompileToAction ? new Type[state.Arguments.Count] : new Type[state.Arguments.Count + 1];
for (var i = 0; i < state.Arguments.Count; i++)
{
paramTypes[i] = state.Arguments[i].Type;
}
if (state.CompileToAction)
{
lambda = Expression.Lambda(Expression.GetActionType(paramTypes), expression, state.Arguments);
}
else
{
var returnType = state.ReturnType ?? state.RawReturnType;
paramTypes[paramTypes.Length - 1] = returnType;
expression = ExpressionTreeExtensions.AdjustReturnType(null, expression, returnType);
lambda = Expression.Lambda(expression, state.Arguments);
if (!ReferenceEquals(returnType, lambda.ReturnType))
{
throw new CompilationException(string.Format("Expected return type: {0}. Real return type: {1}", returnType.FullName, lambda.ReturnType.FullName));
}
}
if (lambda.Parameters.Count != state.Arguments.Count)
{
throw new CompilationException(string.Format("Expected number of arguments: {0}. Real number: {1}", state.Arguments.Count, lambda.Parameters.Count));
}
for (var i = 0; i < lambda.Parameters.Count; i++)
{
if (!ReferenceEquals(lambda.Parameters[i].Type, state.Arguments[i].Type))
{
throw new CompilationException(
string.Format("Expected type of argument {0}: {1}. Real type: {2}", i, state.Arguments[i].Type.FullName, lambda.Parameters[i].Type.FullName));
}
}
return lambda.Compile();
}
示例5: VisitReducible
public Expression VisitReducible(Expression node)
{
Debug.Assert(node.CanReduce);
return Visit(node.Reduce());
}