public static string GetReflectedFullName(SqlTagContext ctx, BaseTag tag, string propertyName)
        {
            if (ctx == null)
                throw new ArgumentNullException("ctx");
            if (tag == null)
                throw new ArgumentNullException("tag");
            if (propertyName == null)
                throw new ArgumentNullException("propertyName");

            var currentIteratorContext = ctx.GetAttribute(tag) as IterateContext;

            // is current tag an iterate?
            if (currentIteratorContext != null)
            {
                propertyName = String.Format("{0}[{1}]", propertyName, currentIteratorContext.Index);
            }

            var parentIteratorTag = FindParentIteratorTag(ctx, tag);

            // is current node a child of another iterate node?
            if (parentIteratorTag != null)
                return BuildReflectedFullName(ctx, parentIteratorTag, propertyName);

            return propertyName;
        }
        public static bool ReplacePropertyIndexerWithFullName(SqlTagContext ctx, BaseTag tag, StringBuilder bodyContent)
        {
            if (ctx == null)
                throw new ArgumentNullException("ctx");
            if (tag == null)
                throw new ArgumentNullException("tag");
            if (bodyContent == null)
                throw new ArgumentNullException("bodyContent");

            string propertyName = tag.Property;

            if (propertyName == null)
                propertyName = String.Empty;

            if (propertyName.StartsWith(THIS_ENUMERATOR_PLACEHOLDER))
            {
                var builtPropertyName = GetReflectedFullName(ctx, tag, propertyName);
                var suffix = String.Empty;

                // if the property name is just the current item reference, then do not suffix the property name with a "."
                if (propertyName != THIS_ENUMERATOR_PLACEHOLDER)
                    suffix = ".";

                StringHandler.Replace(bodyContent, THIS_ENUMERATOR_PLACEHOLDER, builtPropertyName + suffix);

                return true;
            }

            return false;
        }
        public object GetMemberPropertyValue(SqlTagContext ctx, BaseTag tag, object parameterObject)
        {
            if (ctx == null)
                throw new ArgumentNullException("ctx");
            if (tag == null)
                throw new ArgumentNullException("tag");

            return GetMemberValue(ctx, tag, tag.Property, parameterObject);
        }
        private IterateContext FindParentIteratorContext(SqlTagContext ctx, BaseTag tag)
        {
            if (tag.Parent is Iterate)
                return ctx.GetAttribute(tag.Parent) as IterateContext;

            var parentBaseTag = tag.Parent as BaseTag;

            if (tag.Parent == null || parentBaseTag == null)
                return null;

            return FindParentIteratorContext(ctx, parentBaseTag);
        }
        public object GetMemberValue(SqlTagContext ctx, BaseTag tag, string propertyName, object parameterObject)
        {
            var iteratorContext = FindParentIteratorContext(ctx, tag);

            if (iteratorContext != null)
            {
                var indexOfIndexer = propertyName.IndexOf(ReflectionMapper.THIS_ENUMERATOR_PLACEHOLDER);

                if (indexOfIndexer == 0)
                {
                    parameterObject = iteratorContext.Current;
                    propertyName = propertyName.Substring(indexOfIndexer + ReflectionMapper.THIS_ENUMERATOR_PLACEHOLDER.Length);
                }
            }

            return ObjectProbe.GetMemberValue(parameterObject, propertyName, _accessorFactory);
        }
        private static Iterate FindParentIteratorTag(SqlTagContext ctx, BaseTag tag)
        {
            if (tag.Parent is Iterate)
                return tag.Parent as Iterate;

            var parentBaseTag = tag.Parent as BaseTag;

            if (tag.Parent == null || parentBaseTag == null)
                return null;

            return FindParentIteratorTag(ctx, parentBaseTag);
        }
Beispiel #7
0
 internal string ReplaceIterateCurrentProperty(BaseTag baseTag)
 {
     return ReflectionMapper.GetReflectedFullName(this, baseTag, baseTag.Property);
 }
Beispiel #8
0
        internal IList<BindingReplacement> BuildPropertyBindingReplacements(BaseTag tag)
        {
            if (tag == null)
                throw new ArgumentNullException("tag");

            return InlineParameterMapParser.BuildBindingReplacements(_bindings, new StringBuilder(tag.Property));
        }
        /// <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);
        }