static Expression<Action<Url, RouteValueDictionary>> CreatePropertyPusher(Type urlType, MethodInfo addMethod,
PropertyInfo property)
{
var url = Expression.Parameter(typeof (Url), "url");
var values = Expression.Parameter(typeof (RouteValueDictionary), "values");
var typedUrl = Expression.TypeAs(url, urlType);
Expression getPropertyValue = Expression.Property(typedUrl, property);
if (property.PropertyType.IsValueType)
{
// need to box the value type.
getPropertyValue = Expression.TypeAs(getPropertyValue, typeof (object));
}
var addValue = Expression.Call(values, addMethod, Expression.Constant(property.Name, typeof (string)),
getPropertyValue);
return Expression.Lambda<Action<Url, RouteValueDictionary>>(addValue, url, values);
}