How can I determine the type of a ConstantExpression Value when it is null? I have previously been detecting the type using the following code, but it causes a null exception when the ConstantExpression Value is null.
static Type GetType(Expression expression)
{
//causes exception when ((ConstantExpression)expression).Value is null
if (expression is ConstantExpression)
return ((ConstantExpression)expression).Value.GetType();
//Check other types
}
Imagine my Expression was created similar to this:-
int? value = null;
ConstantExpression expression = Expression.Constant(value);
And I would like to determine the type int?
Aucun commentaire:
Enregistrer un commentaire