I have a property defined as Expression<Func<Kitten, object>>
which is c => c.KittenAge
, where KittenAge
is an int?
I want to get the type of this.
My code is:
Expression<Func<Kitten, object>> property = c => c.KittenAge;
var unaryExpression = property.Body as UnaryExpression;
if (Nullable.GetUnderlyingType(unaryExpression.Type) == null)
{
// Error, must be nullable
}
Unfortunately, the error line is always hit because the Type
is System.Object
. How can I get the type of int?
from the expression?
Aucun commentaire:
Enregistrer un commentaire