Snooze.Url.CreatePropertyPusher C# (CSharp) Method

CreatePropertyPusher() static private method

static private CreatePropertyPusher ( Type urlType, MethodInfo addMethod, PropertyInfo property ) : RouteValueDictionary>>.Expression
urlType System.Type
addMethod System.Reflection.MethodInfo
property System.Reflection.PropertyInfo
return RouteValueDictionary>>.Expression
        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);
        }