示例#1
0
        /// <summary>
        /// Gets the value of the property with the given <paramref name="propertyName"/>, or <see cref="string.Empty"/> if a property with that name does not exist on this object or is <c>null</c>.
        /// </summary>
        /// <remarks>
        /// To avoid conflicts with template syntax, avoid using the following symbols in the property name
        /// <list type="bullet">
        ///     <item><description>:</description></item>
        ///     <item><description>%</description></item>
        ///     <item><description>$</description></item>
        ///     <item><description>#</description></item>
        ///     <item><description>&gt;</description></item>
        ///     <item><description>&lt;</description></item>
        ///     <item><description>"</description></item>
        ///     <item><description>'</description></item>
        /// </list>
        /// </remarks>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="format">
        /// A numeric or DateTime format string, or one of the string formatting options accepted by <see cref="TemplateEngine.FormatString"/>,
        /// or <c>null</c> or <see cref="string.Empty"/> to apply the default format.
        /// </param>
        /// <returns>The string representation of the value of this instance as specified by <paramref name="format"/>.</returns>
        public override string GetValue(string propertyName, string format)
        {
            if (propertyName == null)
            {
                throw new ArgumentNullException("propertyName");
            }

            switch (propertyName.ToUpperInvariant())
            {
            case "MULTIPLE CATEGORIES":
            case "MULTIPLECATEGORIES":
                IEnumerable <Category> categories = CategoryCollection.Load(this.PortalId);
                var moduleCategoryIds             = ModuleSettings.GetCategoriesFor(new FakeModuleControlBase(Utility.DesktopModuleName, this.ModuleContext.Configuration));
                if (moduleCategoryIds.Any())
                {
                    var categoryIdsWithAncestor = Utility.AddAncestorIds(moduleCategoryIds.ToArray(), categories.ToArray(), true);
                    categories = categories.Where(category => categoryIdsWithAncestor.Contains(category.Id));
                }

                return((categories.Count() > 1).ToString(CultureInfo.InvariantCulture));
            }

            return(base.GetValue(propertyName, format));
        }