Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with System.Linq.Expressions.LogicalBinaryExpression class?

I'm trying to parse Expression and at some point I have to parse expressions with type System.Linq.Expressions.LogicalBinaryExpression. This class name I take from debug watch. expression.GetType().ToString() equals "System.Linq.Expressions.LogicalBinaryExpression". But I cant see this class in System.Linq.Expressions namespace. Nowhere at all. The same thing with MethodBinaryExpression class.

In order to check type I really prefer to write

  • expression is LogicalBinaryExpression or
  • expression.GetType() = typeof(LogicalBinaryExpression ) but definitely not
  • expression.GetType().ToString() == "System.Linq.Expressions.LogicalBinaryExpression"

So now I just have error

The type or namespace name 'LogicalBinaryExpression' does not exist in the namespace 'System.Linq.Expressions' (are you missing an assembly reference?)

How this possible?

like image 300
Vitalii Korsakov Avatar asked Feb 11 '12 15:02

Vitalii Korsakov


1 Answers

LogicalBinaryExpression is internal, so:

  1. It's more difficult to get is as a Type, you can't simply use typeof(LogicalBinaryExpression) or x is LogicalBinaryExpression.
  2. You won't find any documentation about it.
  3. You shouldn't use it at all. It's an implementation detail that can change any time.

You should either check for BinaryExpression, or check the NodeType of the expression.

The same applies to MethodBinaryExpression.

like image 112
svick Avatar answered Sep 18 '22 23:09

svick