本文整理汇总了C#中System.Linq.Expressions.Expression.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.GetType方法的具体用法?C# Expression.GetType怎么用?C# Expression.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq.Expressions.Expression
的用法示例。
在下文中一共展示了Expression.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMutator
public static IMutableExpression GetMutator(Expression expression)
{
if (expression is BinaryExpression)
return new BinaryExpressionMutator((BinaryExpression)expression);
if (expression is ConditionalExpression)
return new ConditionalExpressionMutator((ConditionalExpression)expression);
if (expression is ConstantExpression)
return new ConstantExpressionMutator((ConstantExpression)expression);
if (expression is InvocationExpression)
return new InvocationExpressionMutator((InvocationExpression)expression);
if (expression is LambdaExpression)
return new LambdaExpressionMutator((LambdaExpression)expression);
if (expression is MemberExpression)
return new MemberExpressionMutator((MemberExpression)expression);
if (expression is MethodCallExpression)
return new MethodCallExpressionMutator((MethodCallExpression)expression);
if (expression is NewExpression)
return new NewExpressionMutator((NewExpression)expression);
if (expression is NewArrayExpression)
return new NewArrayExpressionMutator((NewArrayExpression)expression);
if (expression is MemberInitExpression)
return new MemberInitExpressionMutator((MemberInitExpression)expression);
if (expression is ListInitExpression)
return new ListInitExpressionMutator((ListInitExpression)expression);
if (expression is ParameterExpression)
return new ParameterExpressionMutator((ParameterExpression)expression);
if (expression is TypeBinaryExpression)
return new TypeBinaryExpressionMutator((TypeBinaryExpression)expression);
if (expression is UnaryExpression)
return new UnaryExpressionMutator((UnaryExpression)expression);
throw Error.BadArgument("S0064: Unknown Expression Type '{0}'", expression.GetType());
}
示例2: EqualsExact
internal static Boolean EqualsExact(this Expression self, Expression other)
{
return self.GetType() == other.GetType() &&
self.GetType().GetConvertibleTypes()
.SelectMany(t => t.GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
.All(f => EqualsExact(f.GetValue(self), f.GetValue(other)));
}
示例3: ProcessExpression
protected virtual void ProcessExpression(Expression expression)
{
var type = expression.GetType();
if (type == typeof(MethodCallExpression)
|| typeof(MethodCallExpression).IsAssignableFrom(type))
ProcessMethodCall(expression as MethodCallExpression);
else if (type == typeof(BinaryExpression)
|| typeof(BinaryExpression).IsAssignableFrom(type))
ProcessBinary(expression as BinaryExpression);
else if (type == typeof(ConstantExpression)
|| typeof(ConstantExpression).IsAssignableFrom(type))
ProcessConstant(expression as ConstantExpression);
else if (type == typeof(MemberExpression)
|| typeof(MemberExpression).IsAssignableFrom(type))
ProcessMemberAccess(expression as MemberExpression);
else if (type == typeof(UnaryExpression)
|| typeof(UnaryExpression).IsAssignableFrom(type))
ProcessUnary(expression as UnaryExpression);
else if (type == typeof(LambdaExpression)
|| typeof(LambdaExpression).IsAssignableFrom(type))
ProcessLambda(expression as LambdaExpression);
else if (type == typeof(NewArrayExpression))
ProcessNewArrayExpression(expression as NewArrayExpression);
else if (type.BaseType == typeof(LambdaExpression)
|| typeof(LambdaExpression).IsAssignableFrom(type.BaseType))
ProcessLambda(expression as LambdaExpression);
}
示例4: Parse
public Node Parse(Expression e)
{
try
{
return ParseExpression((dynamic) e);
}
catch (RuntimeBinderException exception)
{
throw new Exception(string.Format("Unable to dispatch expression of type {0} with node type of {1}", e.GetType().Name, e.NodeType), exception);
}
}
示例5: MemberInfo
public static MemberInfo MemberInfo(Expression exp)
{
Contract.Requires<ArgumentNullException>(exp != null);
var lambda = exp as LambdaExpression;
if (lambda == null)
throw new ArgumentException("exp is no LamdaExpression but a " + exp.GetType().FullName);
var body = lambda.Body as MemberExpression;
if (body == null)
throw new ArgumentException("exp.Body is no Member expression but a " + lambda.Body.GetType());
return body.Member;
}
示例6: ExtractMember
private static MemberInfo ExtractMember(Expression expr)
{
switch (expr.NodeType)
{
case ExpressionType.Lambda:
return ExtractMember(((LambdaExpression)expr).Body);
case ExpressionType.MemberAccess:
return ((MemberExpression)expr).Member;
case ExpressionType.Convert:
return ExtractMember(((UnaryExpression)expr).Operand);
}
throw new NotSupportedException(String.Format("Expression of type {0}[{1}] is not supported", expr.NodeType, expr.GetType().Name));
}
示例7: Parse
public static Node Parse(Expression e)
{
if (e.NodeType == ExpressionType.ArrayIndex)
{
return ArrayIndex((BinaryExpression)e);
}
if (e is BinaryExpression)
{
return Binary((BinaryExpression)e, Util.NaturalOperators[e.NodeType]);
}
if (e is MemberExpression)
{
return Member((MemberExpression)e);
}
if (e is ConstantExpression)
{
return Constant((ConstantExpression)e);
}
if (e is MethodCallExpression)
{
return MethodCall((MethodCallExpression)e);
}
if (e is ConditionalExpression)
{
return Conditional((ConditionalExpression)e);
}
if (e is NewArrayExpression)
{
return NewArray((NewArrayExpression)e);
}
if (e is UnaryExpression)
{
return Unary((UnaryExpression)e);
}
if (e.NodeType == ExpressionType.Lambda)
{
return Lambda(e);
}
if (e is TypeBinaryExpression)
{
return TypeBinary((TypeBinaryExpression)e);
}
if(e is NewExpression)
{
return NewObject((NewExpression) e);
}
throw new ArgumentOutOfRangeException("e", string.Format("Can't handle expression of class {0} and type {1}", e.GetType().Name, e.NodeType));
}
示例8: Visit
public override Expression Visit(Expression exp)
{
if (exp != null)
{
for (int i = 0; i < level; i++)
{
Console.Write(" ");
}
Console.WriteLine("{0} - {1}",
exp.NodeType, exp.GetType().Name);
}
level++;
Expression result = base.Visit(exp);
level--;
return result;
}
示例9: ParseUnaryExpression
private static FilterExpression ParseUnaryExpression(Expression expression)
{
var unaryExpression = (expression as UnaryExpression).Operand;
var filterExpression = ParseLinqExpression(unaryExpression);
switch (expression.NodeType)
{
case ExpressionType.Not:
return !filterExpression;
case ExpressionType.Convert:
return filterExpression;
case ExpressionType.Negate:
return -filterExpression;
}
throw new NotSupportedException(string.Format("Not supported expression of type {0} ({1}): {2}",
expression.GetType(), expression.NodeType, expression));
}
示例10: CreateWithoutResolve
private ExpressionNode CreateWithoutResolve(Expression expression)
{
if (expression is BinaryExpression) return new BinaryExpressionNode(this, expression as BinaryExpression);
if (expression is ConditionalExpression) return new ConditionalExpressionNode(this, expression as ConditionalExpression);
if (expression is ConstantExpression) return new ConstantExpressionNode(this, expression as ConstantExpression);
if (expression is InvocationExpression) return new InvocationExpressionNode(this, expression as InvocationExpression);
if (expression is LambdaExpression) return new LambdaExpressionNode(this, expression as LambdaExpression);
if (expression is ListInitExpression) return new ListInitExpressionNode(this, expression as ListInitExpression);
if (expression is MemberExpression) return new MemberExpressionNode(this, expression as MemberExpression);
if (expression is MemberInitExpression) return new MemberInitExpressionNode(this, expression as MemberInitExpression);
if (expression is MethodCallExpression) return new MethodCallExpressionNode(this, expression as MethodCallExpression);
if (expression is NewArrayExpression) return new NewArrayExpressionNode(this, expression as NewArrayExpression);
if (expression is NewExpression) return new NewExpressionNode(this, expression as NewExpression);
if (expression is ParameterExpression) return new ParameterExpressionNode(this, expression as ParameterExpression);
if (expression is TypeBinaryExpression) return new TypeBinaryExpressionNode(this, expression as TypeBinaryExpression);
if (expression is UnaryExpression) return new UnaryExpressionNode(this, expression as UnaryExpression);
throw new ArgumentException("Unknown expression of type " + expression.GetType());
}
示例11: ParseLinqExpression
private static FilterExpression ParseLinqExpression(Expression expression)
{
switch (expression.NodeType)
{
case ExpressionType.MemberAccess:
return ParseMemberExpression(expression);
case ExpressionType.Constant:
return new FilterExpression((expression as ConstantExpression).Value);
case ExpressionType.Not:
case ExpressionType.Convert:
case ExpressionType.Negate:
return ParseUnaryExpression(expression);
case ExpressionType.Equal:
case ExpressionType.NotEqual:
case ExpressionType.LessThan:
case ExpressionType.LessThanOrEqual:
case ExpressionType.GreaterThan:
case ExpressionType.GreaterThanOrEqual:
case ExpressionType.And:
case ExpressionType.AndAlso:
case ExpressionType.Or:
case ExpressionType.OrElse:
case ExpressionType.Add:
case ExpressionType.AddChecked:
case ExpressionType.Subtract:
case ExpressionType.SubtractChecked:
case ExpressionType.Multiply:
case ExpressionType.MultiplyChecked:
case ExpressionType.Divide:
case ExpressionType.Modulo:
return ParseBinaryExpression(expression);
}
throw new NotSupportedException(string.Format("Not supported expression of type {0} ({1}): {2}",
expression.GetType(), expression.NodeType, expression));
}
示例12: Visit
private string Visit(Expression expression)
{
switch (expression.NodeType)
{
case ExpressionType.Lambda:
return this.VisitLambda((LambdaExpression) expression);
case ExpressionType.Call:
return this.MethodMethodCall((MethodCallExpression) expression);
case ExpressionType.MemberAccess:
return this.VisitMember((MemberExpression) expression);
case ExpressionType.Constant:
return this.VisitConstant((ConstantExpression) expression);
case ExpressionType.Multiply:
case ExpressionType.Subtract:
case ExpressionType.Add:
return this.VisitBinary((BinaryExpression) expression);
}
throw new NotImplementedException(expression.GetType().FullName);
}
示例13: VisitIf
private static Expression VisitIf(Expression node, Type type, Func<Expression, Expression> func)
{
return node.GetType() == type ? func(node) : node;
}
示例14: ParseBinaryExpression
private static FilterExpression ParseBinaryExpression(Expression expression)
{
var binaryExpression = expression as BinaryExpression;
var leftExpression = ParseLinqExpression(binaryExpression.Left);
var rightExpression = ParseLinqExpression(binaryExpression.Right);
switch (expression.NodeType)
{
case ExpressionType.Equal:
return leftExpression == rightExpression;
case ExpressionType.NotEqual:
return leftExpression != rightExpression;
case ExpressionType.LessThan:
return leftExpression < rightExpression;
case ExpressionType.LessThanOrEqual:
return leftExpression <= rightExpression;
case ExpressionType.GreaterThan:
return leftExpression > rightExpression;
case ExpressionType.GreaterThanOrEqual:
return leftExpression >= rightExpression;
case ExpressionType.And:
case ExpressionType.AndAlso:
return leftExpression && rightExpression;
case ExpressionType.Or:
case ExpressionType.OrElse:
return leftExpression || rightExpression;
case ExpressionType.Add:
case ExpressionType.AddChecked:
return leftExpression + rightExpression;
case ExpressionType.Subtract:
case ExpressionType.SubtractChecked:
return leftExpression - rightExpression;
case ExpressionType.Multiply:
case ExpressionType.MultiplyChecked:
return leftExpression * rightExpression;
case ExpressionType.Divide:
return leftExpression / rightExpression;
case ExpressionType.Modulo:
return leftExpression % rightExpression;
}
throw new NotSupportedException(string.Format("Not supported expression of type {0} ({1}): {2}",
expression.GetType(), expression.NodeType, expression));
}
示例15: WriteHeader
private void WriteHeader(Expression exp)
{
WriteLine("{0}:{1} Type={2}", PublicClassName(exp.GetType()), exp.NodeType, FriendlyClassName(exp.Type));
}