Example #1
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            if (For == null)
            {
                throw new ArgumentNullException(ForAttributeName);
            }
            if (KeyName == null && !FromRow.HasValue)
            {
                throw new ArgumentNullException(KeyAttributeName);
            }
            var rc = context.GetFatherReductionContext();

            if (rc.RowParsingDisabled)
            {
                output.TagName = string.Empty;
                output.Content.SetHtmlContent(string.Empty);
                return;
            }
            var nc = new ReductionContext(TagTokens.Row, 0, rc.Defaults);

            context.SetChildrenReductionContext(nc);
            await output.GetChildContentAsync();

            RowType inherit = null;

            if (FromRow.HasValue)
            {
                var count = 0;
                foreach (var item in rc.Results)
                {
                    if (item.Token == TagTokens.Row)
                    {
                        if (FromRow.Value == count)
                        {
                            inherit = item.Result as RowType;
                            continue;
                        }
                        else
                        {
                            count++;
                        }
                    }
                }
            }
            var collector = new RowCollector(nc, FromRow);
            var res       = collector.Process(this, rc.Defaults);

            if (res != null)
            {
                rc.Results.Add(new ReductionResult(TagTokens.Row, 0, res));
            }
            output.TagName = string.Empty;
            output.Content.SetHtmlContent(string.Empty);
        }