How to check the type of a Parameter in an Expression Tree (similar to 'is' keyword)
-
25-09-2019 - |
Question
How do I check the type of a Parameter in an Expression Tree (and get the Expression Tree equivalent of a bool
if it the right type)? If it were normal code, I would do this:
if(myObj is int)
I see there is a Expression.Convert
method but this converts the object instead of just checking its type.
EDIT: I found the answer, you use a Expression.TypeIs
Solution
You can use the Expression.TypeIs
method :
var isExpression = Expression.TypeIs(parameterExpression, typeof(SomeType));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow