Exemplo n.º 1
0
        public static IEnumerable <LoopItem <TModel, TData> > LoopItems <TData>(HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, IEnumerable <TData> > > listExpression, Func <TModel, int, TData> listFunc, IEnumerable <TData> enumerable)
        {
            var i          = 0;
            var enumerator = enumerable.GetEnumerator();
            var next       = enumerator.MoveNext();

            var indexedExp = GetCurrentIndexedExpression(listExpression);

            while (next)
            {
                var current = enumerator.Current;
                next = enumerator.MoveNext();

                var loopInfo = new LoopItem <TModel, TData> .LoopInfo(indexedExp(i), htmlHelper,
                                                                      index : i,
                                                                      isFirst : i == 0,
                                                                      isLast : next == false,
                                                                      isEven : i % 2 == 0,
                                                                      isOdd : i % 2 != 0);

                yield return(new LoopItem <TModel, TData>(listFunc, htmlHelper, current, loopInfo));

                i++;
            }
        }
Exemplo n.º 2
0
        public static IEnumerable <LoopItem <TModel, TData> > Loop <TModel, TData>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, IEnumerable <TData> > > listExpression)
        {
            var enumerable = listExpression.Compile().Invoke(htmlHelper.ViewData.Model);
            var listFunc   = LoopItem <TModel, TData> .GetCurrentIndexedExpressionWithIntParam(listExpression).Compile();

            return(LoopItem <TModel, TData> .LoopItems(htmlHelper, listExpression, listFunc, enumerable));
        }
Exemplo n.º 3
0
        public IEnumerable <LoopItem <TModel, TData> > Loop <TData>(Expression <Func <T, IEnumerable <TData> > > listExpression)
        {
            var newExpression = CombineExpression(listExpression);

            var compiledFunc2 = (Tuple <Func <T, IEnumerable <TData> >, Func <TModel, int, TData> >)cache.GetOrAdd(typeof(TData), y =>
            {
                var accessor = GetCurrentIndexedExpressionWithIntParam(newExpression).Compile();
                var tuple    = new Tuple <Func <T, IEnumerable <TData> >, Func <TModel, int, TData> >(listExpression.Compile(), accessor);
                return(tuple);
            });

            var enumerable = compiledFunc2.Item1(_listFunc.Invoke(_htmlHelper.ViewData.Model, Info.Index));

            return(LoopItem <TModel, TData> .LoopItems(_htmlHelper, newExpression, compiledFunc2.Item2, enumerable));
        }
Exemplo n.º 4
0
 public static string IdFor <TModel, T>(this LoopItem <TModel, T> loopItem, Expression <Func <T, object> > expression)
 {
     return(TagGenerator.BuildRequestData(loopItem.Info.HtmlHelper.ViewContext, loopItem.Info.TranslateExpression(expression)).Id);
 }