Example #1
0
        internal static object ConvertChecked(object value, Type targetType)
        {
            if (value == null)
            {
                return(null);
            }

            var type = Nullable.GetUnderlyingType(targetType) ?? targetType;

            try
            {
                return(RuntimeMethodInvoker.InvokeFuncCached <RuntimeType1, RuntimeType1>(
                           ConvertChecked <RuntimeType1>, new RuntimeTypeBinding {
                    new RuntimeType1(type)
                }, value));
            }
            catch (TargetInvocationException e)
            {
                if (e.InnerException is OverflowException)
                {
                    throw e.InnerException;
                }
                throw;
            }
        }
        private ProcessingResult ProcessThenBy(MethodCallExpression query, ProcessingResult parentResult, DataContext context, bool descending)
        {
            if ((!parentResult.IsDeferred()) && (parentResult.Result is IOrderedQueryable))
            {
                return(ProcessingResult.Unsuccessful);
            }

            var keySelector = GetKeySelector(query);
            var comparer    = GetComparer(query);

            var keysResult = GetKeys(keySelector, parentResult, context);

            if (!keysResult.IsSuccess)
            {
                return(ProcessByDefault(query, parentResult, context));
            }

            var keyType    = keySelector.ReturnType;
            var sourceType = parentResult.IsDeferred()
                ? typeof(NodeReference)
                : QueryProcessingHelper.GetSourceParameterType(query);

            Func <OrderedEnumerable <RuntimeType1>, List <RuntimeType2>, IComparer <RuntimeType2>, bool,
                  OrderedEnumerable <RuntimeType1> > func = AppendOrderedEnumerable;

            var orderedEnumerable = RuntimeMethodInvoker.InvokeFuncCached(func,
                                                                          new RuntimeTypeBinding {
                new RuntimeType1(sourceType), new RuntimeType2(keyType)
            }, parentResult.Result,
                                                                          keysResult.Result, comparer, descending);

            return(new ProcessingResult(true, orderedEnumerable));
        }
Example #3
0
        internal static object TypeAsOperation(object value, Type targetType)
        {
            if (value == null)
            {
                return(null);
            }

            return(RuntimeMethodInvoker.InvokeFuncCached <RuntimeType1, RuntimeType1>(TypeAsOperation <RuntimeType1>,
                                                                                      new RuntimeTypeBinding {
                new RuntimeType1(targetType)
            }, value));
        }
Example #4
0
        public ProcessingResult ProcessQuery(MethodCallExpression query, ProcessingResult parentResult, DataContext context)
        {
            var itemType = parentResult.IsDeferred()
                ? typeof(NodeReference)
                : QueryProcessingHelper.GetSourceParameterType(query);

            var result = RuntimeMethodInvoker.InvokeFuncCached <IEnumerable <RuntimeType1>, IEnumerable <RuntimeType1> >(
                Reverse, new RuntimeTypeBinding {
                new RuntimeType1(itemType)
            }, parentResult.Result);

            return(new ProcessingResult(true, result));
        }
        public ProcessingResult ProcessQuery(MethodCallExpression query, ProcessingResult parentResult, DataContext context)
        {
            var elementType = QueryProcessingHelper.GetSourceParameterType(query);

            var items    = parentResult.GetLoadedItems(elementType);
            var comparer = query.Arguments.Count > 1 ? ((ConstantExpression)query.Arguments[1]).Value : null;

            var result = RuntimeMethodInvoker.InvokeFuncCached <IEnumerable <RuntimeType1>, IEqualityComparer <RuntimeType1>, List <RuntimeType1> >(
                Distinct, new RuntimeTypeBinding {
                new RuntimeType1(elementType)
            }, items, comparer);

            return(new ProcessingResult(true, result));
        }
Example #6
0
        internal static object ConvertUnchecked(object value, Type targetType)
        {
            if (value == null)
            {
                return(null);
            }

            var type = Nullable.GetUnderlyingType(targetType) ?? targetType;

            return(RuntimeMethodInvoker.InvokeFuncCached <RuntimeType1, RuntimeType1>(
                       ConvertUnchecked <RuntimeType1>, new RuntimeTypeBinding {
                new RuntimeType1(type)
            }, value));
        }
        private static ProcessingResult ProcessByDefault(MethodCallExpression query, ProcessingResult parentResult, DataContext context)
        {
            if (!parentResult.IsDeferred())
            {
                return(QueryProcessingHelper.ProcessQueryByDefault(query, parentResult, context));
            }

            Func <IDeferredOrderedEnumerable, IOrderedEnumerable <RuntimeType1> > func = GetLoadedOrderedEnumerable <RuntimeType1>;

            var loadedEnumerable = RuntimeMethodInvoker.InvokeFuncCached(func,
                                                                         new RuntimeTypeBinding {
                new RuntimeType1(QueryProcessingHelper.GetSourceParameterType(query))
            },
                                                                         parentResult.Result);

            return(QueryProcessingHelper.ProcessQueryByDefault(query, new ProcessingResult(true, loadedEnumerable), context));
        }
        public ProcessingResult ProcessQuery(MethodCallExpression query, ProcessingResult parentResult, DataContext context)
        {
            var source1 = parentResult.GetLoadedItems(QueryProcessingHelper.GetSourceParameterType(query));

            var constantArgument = query.Arguments[1] as ConstantExpression;

            if (constantArgument == null)
            {
                return(ProcessingResult.Unsuccessful);
            }

            var source2  = constantArgument.Value;
            var comparer = query.Arguments.Count > 2 ? ((ConstantExpression)query.Arguments[2]).Value : null;

            var sourceType = QueryProcessingHelper.GetSourceParameterType(query);

            Func <MethodCallExpression, IEnumerable <RuntimeType1>, IEnumerable <RuntimeType1>,
                  IEqualityComparer <RuntimeType1>, ProcessingResult> func = ProcessQuery;

            return((ProcessingResult)RuntimeMethodInvoker.InvokeFuncCached(
                       func, new RuntimeTypeBinding {
                new RuntimeType1(sourceType)
            }, query, source1, source2, comparer));
        }