Example #1
0
        private static IOrderedQueryable <T> DynamicOrderBy <T>(IQueryable <T> query, OrderByItem orderBy)
        {
            var func = MethodHelpers.GetMethodInfo(DynamicOrderBy <T, object>, query, orderBy)
                       .GetGenericMethodDefinition()
                       .MakeGenericMethod(typeof(T), orderBy.Expression.PropertyInfo().PropertyType);

            return((IOrderedQueryable <T>)func.Invoke(null, new object[] { query, orderBy }));
        }
        private IQueryable ApplyFilter(IQueryable query, QueryContext context)
        {
            var method = MethodHelpers.GetMethodInfo(ApplyFilter <object>, default(IQueryable <object>), context)
                         .GetGenericMethodDefinition()
                         .MakeGenericMethod(query.ElementType);

            return((IQueryable)method.Invoke(this, new object[] { query, context }));
        }
Example #3
0
        public DefaultFunctionSource()
        {
            string   refString  = string.Empty;
            DateTime refDate    = default(DateTime);
            decimal  refDecimal = 0m;
            double   refDouble  = 0.0;

            _functionMap = new Dictionary <string, MemberInfo[]>(StringComparer.OrdinalIgnoreCase)
            {
                // String functions
                // { "substringof", },
                { "endswith", new[] { MethodHelpers.GetMethodInfo(() => refString.EndsWith(refString)) } },
                { "startswith", new[] { MethodHelpers.GetMethodInfo(() => refString.StartsWith(refString)) } },
                { "length", new[] { MethodHelpers.GetPropertyInfo(() => refString.Length) } },
                { "indexof", new[] { MethodHelpers.GetMethodInfo(() => refString.IndexOf(refString)) } },
                { "replace", new[] { MethodHelpers.GetMethodInfo(() => refString.Replace(refString, refString)) } },
                {
                    "substring",
                    new[]
                    {
                        MethodHelpers.GetMethodInfo(() => refString.Substring(0)),
                        MethodHelpers.GetMethodInfo(() => refString.Substring(0, 0))
                    }
                },
                { "tolower", new[] { MethodHelpers.GetMethodInfo(() => refString.ToLower()) } },
                { "toupper", new[] { MethodHelpers.GetMethodInfo(() => refString.ToUpper()) } },
                { "trim", new[] { MethodHelpers.GetMethodInfo(() => refString.Trim()) } },
                { "concat", new[] { MethodHelpers.GetMethodInfo(string.Concat, refString, refString) } },

                // Date functions
                { "day", new[] { MethodHelpers.GetPropertyInfo(() => refDate.Day) } },
                { "hour", new[] { MethodHelpers.GetPropertyInfo(() => refDate.Hour) } },
                { "minute", new[] { MethodHelpers.GetPropertyInfo(() => refDate.Minute) } },
                { "month", new[] { MethodHelpers.GetPropertyInfo(() => refDate.Month) } },
                { "second", new[] { MethodHelpers.GetPropertyInfo(() => refDate.Second) } },
                { "year", new[] { MethodHelpers.GetPropertyInfo(() => refDate.Year) } },

                // Math functions
                {
                    "round",
                    new[]
                    {
                        MethodHelpers.GetMethodInfo(() => Math.Round(refDecimal)),
                        MethodHelpers.GetMethodInfo(() => Math.Round(refDouble))
                    }
                },
                {
                    "floor",
                    new[]
                    {
                        MethodHelpers.GetMethodInfo(() => Math.Floor(refDecimal)),
                        MethodHelpers.GetMethodInfo(() => Math.Floor(refDouble))
                    }
                },
                {
                    "ceiling",
                    new[]
                    {
                        MethodHelpers.GetMethodInfo(() => Math.Ceiling(refDecimal)),
                        MethodHelpers.GetMethodInfo(() => Math.Ceiling(refDouble))
                    }
                }
            };
        }