Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="tag"></param>
        /// <param name="parameterObject"></param>
        /// <returns></returns>
        public override int DoStartFragment(SqlTagContext ctx, SqlTag tag, object parameterObject)
        {
            IterateContext iterate = (IterateContext)ctx.GetAttribute(tag);

            if (iterate == null)
            {
                string propertyName = ((BaseTag)tag).Property;
                object collection;
                if (propertyName != null && propertyName.Length > 0)
                {
                    collection = ObjectProbe.GetMemberValue(parameterObject, propertyName, this.AccessorFactory);
                }
                else
                {
                    collection = parameterObject;
                }
                iterate = new IterateContext(collection);
                ctx.AddAttribute(tag, iterate);
            }
            if (iterate != null && iterate.HasNext)
            {
                return(BaseTagHandler.INCLUDE_BODY);
            }
            else
            {
                return(BaseTagHandler.SKIP_BODY);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="tag"></param>
        /// <param name="parameterObject"></param>
        /// <param name="bodyContent"></param>
        public override void DoPrepend(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent)
        {
            IterateContext iterate = (IterateContext)ctx.GetAttribute(tag);

            if (iterate.IsFirst)
            {
                base.DoPrepend(ctx, tag, parameterObject, bodyContent);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="tag"></param>
        /// <param name="parameterObject"></param>
        /// <param name="bodyContent"></param>
        /// <returns></returns>
        public override int DoEndFragment(SqlTagContext ctx, SqlTag tag,
                                          object parameterObject, StringBuilder bodyContent)
        {
            IterateContext iterate = (IterateContext)ctx.GetAttribute(tag);

            if (iterate.MoveNext())
            {
                string propertyName = ((BaseTag)tag).Property;
                if (propertyName == null)
                {
                    propertyName = "";
                }

                string find    = propertyName + "[]";
                string replace = propertyName + "[" + iterate.Index + "]";                //Parameter-index-Dynamic
                Replace(bodyContent, find, replace);

                if (iterate.IsFirst)
                {
                    string open = ((Iterate)tag).Open;
                    if (open != null)
                    {
                        bodyContent.Insert(0, open);
                        bodyContent.Insert(0, ' ');
                    }
                }
                if (!iterate.IsLast)
                {
                    string conjunction = ((Iterate)tag).Conjunction;
                    if (conjunction != null)
                    {
                        bodyContent.Append(conjunction);
                        bodyContent.Append(' ');
                    }
                }
                if (iterate.IsLast)
                {
                    string close = ((Iterate)tag).Close;
                    if (close != null)
                    {
                        bodyContent.Append(close);
                    }
                }

                return(BaseTagHandler.REPEAT_BODY);
            }
            else
            {
                return(BaseTagHandler.INCLUDE_BODY);
            }
        }