Beispiel #1
0
        /// <summary>
        /// This class is responsible for getting the current iterate item object within an iteration. i.e. The property name starts with "[]."
        /// We do this by navigating up through the parent nodes to determine which of them are iterate elements.
        /// Once found we get the current iteration context item.
        /// If "[]." is not specified, the original approach is used of reflecting the parameterObject to the reflection path specified in the property
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="baseTag"></param>
        /// <param name="parameterObject"></param>
        /// <returns></returns>
        /// <remarks>
        /// Created By: Richard Beacroft
        /// Created Date: 11\10\2013
        /// </remarks>
        protected object GetMemberPropertyValue(SqlTagContext ctx, BaseTag baseTag, object parameterObject)
        {
            if (String.IsNullOrEmpty(baseTag.Property))
            {
                return(parameterObject);
            }
#if dotnet35
            var bindingReplacement = ctx.BuildPropertyBindingReplacements(baseTag).FirstOrDefault();
#else
            BindingReplacement bindingReplacement = null;
            foreach (var replacement in ctx.BuildPropertyBindingReplacements(baseTag))
            {
                bindingReplacement = replacement;
                break;
            }
#endif
            if (bindingReplacement != null)
            {
                if (String.IsNullOrEmpty(bindingReplacement.FullPropertyName))
                {
                    return(bindingReplacement.Value);
                }
                return(_tagPropertyProbe.GetMemberValue(ctx, baseTag, bindingReplacement.FullPropertyName, parameterObject));
            }

            return(_tagPropertyProbe.GetMemberPropertyValue(ctx, baseTag, parameterObject));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="tag"></param>
        /// <param name="parameterObject"></param>
        /// <returns></returns>
        /// Updated By: Richard Beacroft
        /// Updated Date: 11\10\2013
        /// Description: Enables one to be able to have sql text within an iterate element that references the current item as "[]."
        /// This is then parsed, along with any reflection path suffix to get the object instance the used is interested in.
        /// and add it to an attributes collection for later use.
        public override int DoStartFragment(SqlTagContext ctx, SqlTag tag, object parameterObject)
        {
            var iterate = (IterateContext)ctx.GetAttribute(tag);

            if (iterate == null)
            {
                var baseTag = (BaseTag)tag;

                object collection;

                if (!string.IsNullOrEmpty(baseTag.Property))
                {
                    // this will either leave the property name as it is, or if it starts with "[].", the
                    // current iterate context item value will be used, with the rest of the property name
                    // walked to determine the field/property to get the value from.
                    collection = _tagPropertyProbe.GetMemberPropertyValue(ctx, baseTag, parameterObject);
                }
                else
                {
                    collection = parameterObject;
                }

                iterate = new IterateContext(collection);

                ctx.AddAttribute(tag, iterate);

                // if there is another item in the iterate array, then we need to include the body.
                if (iterate.MoveNext())
                {
                    return(INCLUDE_BODY);
                }

                iterate.IsCompleted = true;

                return(SKIP_BODY);
            }

            if (iterate.IsCompleted)
            {
                // reset the context to cater for nested iterations.
                ctx.RemoveAttibute(tag);
                // now re-process the tag which will re-add the now modified tag element back to the attributes collection.
                return(DoStartFragment(ctx, tag, parameterObject));
            }
            else if (iterate.HasNext || iterate.IsLast)
            {
                if (iterate.MoveNext())
                {
                    return(INCLUDE_BODY);
                }
            }

            return(SKIP_BODY);
        }
Beispiel #3
0
        /// <summary>
        /// This class is responsible for getting the current iterate item object within an iteration. i.e. The property name starts with "[]."
        /// We do this by navigating up through the parent nodes to determine which of them are iterate elements.
        /// Once found we get the current iteration context item.
        /// If "[]." is not specified, the original approach is used of reflecting the parameterObject to the reflection path specified in the property
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="baseTag"></param>
        /// <param name="parameterObject"></param>
        /// <returns></returns>
        /// <remarks>
        /// Created By: Richard Beacroft
        /// Created Date: 11\10\2013
        /// </remarks>
        protected object GetMemberPropertyValue(SqlTagContext ctx, BaseTag baseTag, object parameterObject)
        {
            if (String.IsNullOrEmpty(baseTag.Property))
            {
                return(parameterObject);
            }

            var bindingReplacement = ctx.BuildPropertyBindingReplacements(baseTag).FirstOrDefault();

            if (bindingReplacement != null)
            {
                if (String.IsNullOrEmpty(bindingReplacement.FullPropertyName))
                {
                    return(bindingReplacement.Value);
                }
                return(_tagPropertyProbe.GetMemberValue(ctx, baseTag, bindingReplacement.FullPropertyName, parameterObject));
            }

            return(_tagPropertyProbe.GetMemberPropertyValue(ctx, baseTag, parameterObject));
        }