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

.net expression-trees

Question

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?

Accepted Answer

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.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why