Ejemplo n.º 1
0
        /// <summary>
        /// selector: Name,Age,Location
        /// orderBy:
        ///   - ascending  :  +Name,+Age
        ///   - descending :  -Name,-Age
        ///   - mixed (OrderBy, ThenBy) :  +Name,-Age
        /// query: &(Name=Roy)(Age=18)
        /// </summary>
        /// <param name="source"></param>
        /// <param name="selector"></param>
        /// <param name="filter"></param>
        /// <param name="orderBy"></param>
        /// <returns></returns>
        public static IQueryable QueryDynamic(this IQueryable source, string selector, string filter,
                                              string orderBy = null, int?skip = null, int?take = null)
        {
            var outputType = source.ElementType;

            if (selector != null)
            {
                var selectorExpression = SelectorBuilder.Build(source.ElementType, selector, out outputType);
                if (selectorExpression != null)
                {
                    source = source.Provider.CreateQuery(Expression.Call(typeof(Queryable), "Select",
                                                                         new[] { source.ElementType, outputType },
                                                                         source.Expression, selectorExpression));
                }
            }

            if (filter != null)
            {
                var queryExpression = FilterParser.Parse(filter).Build(outputType);
                if (queryExpression != null)
                {
                    source = source.Provider.CreateQuery(Expression.Call(typeof(Queryable), "Where",
                                                                         new[] { outputType },
                                                                         source.Expression, queryExpression));
                }
            }

            if (orderBy != null)
            {
                var isFirstOrder = true;
                foreach (var orderByField in orderBy.Split(",").Where(of => of.Length > 1))
                {
                    var memberName          = orderByField[1..];
Ejemplo n.º 2
0
        public GateController NewDut()
        {
            _selector      = SelectorBuilder.Build();
            _pwmController = MockPwmController;
            _gateStates    = GateStatesBuilder.Build();

            return(new GateController(_selector, _pwmController, _gateStates.Object));
        }