Actual type of an IExpression

Topics: Metadata Model
Jul 25, 2010 at 1:29 PM



IExpression has a ITypeReference Type property that most of the times is a dummy type reference. When I create a mutable MethodCall or a BoundExpression, I don't set them explicitly and CCI metadata is perfectly fine with it. I thought that Type woyld evaluate to the actual type once MethodToCall or Definition are set but that's not the case.

Now I think that CCI has other means to infer the actual type. Is this the case?

If I want to match a list of expressions against the parameters of a method I need to have the actual types. I made a method that does that in the cases that I need but I was wondering if there is a CCI public method that does that already.



Jul 26, 2010 at 5:00 AM

This is a somewhat tricky design problem. The type of an expression can be computed from other information, so each implementation of the expression object model, including the mutable model, might be expected to compute the Type property. However, the computation is not so cheap that caching the result is not important, and caching the result in a mutable implementation is problematic. Consequently, the mutable model ducks the issue by making it the responsibility of the mutator to set the Type property to the appropriate value in all cases.

The IlToCodeModel project contains some type inference code that can generalized and made public, but right now there is no ready made method or that you can just call.