Пример #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 string GetValue([NotNull] string propertyName, string format)
        {
            if (propertyName == null)
            {
                throw new ArgumentNullException("propertyName");
            }

            format = string.IsNullOrEmpty(format) ? null : format;
            switch (propertyName.ToUpperInvariant())
            {
            case "ID":
                return(this.Id.ToString(format, CultureInfo.CurrentCulture));

            case "PARENT":
            case "PARENTID":
                return(this.ParentId.HasValue ? this.ParentId.Value.ToString(format, CultureInfo.CurrentCulture) : string.Empty);

            case "NAME":
            case "TITLE":
                return(TemplateEngine.FormatString(this.Name, format ?? "HTML"));

            case "COLOR":
                return(TemplateEngine.FormatString(this.Color, format ?? "HTML"));

            case "EVENTCOUNT":
            case "EVENT COUNT":
                return(this.EventCount.ToString(format, CultureInfo.CurrentCulture));
            }

            return(string.Empty);
        }
Пример #2
0
        /// <summary>
        /// Gets the value of the property with the given <paramref name="propertyName"/>, or <see cref="F:System.String.Empty"/> if a property with that name does not exist on this object or is <c>null</c>.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param><param name="format">A numeric or DateTime format string, or <c>null</c> or <see cref="F:System.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 string GetValue(string propertyName, string format)
        {
            if (!string.IsNullOrEmpty(propertyName))
            {
                switch (propertyName.ToUpperInvariant())
                {
                case "CONTENT":
                    return(TemplateEngine.FormatString(this.Content, format ?? "RAW"));

                case "ENDDATE":
                case "END DATE":
                    return(this.EndDate.HasValue ? this.EndDate.Value.ToString(format, CultureInfo.CurrentCulture) : string.Empty);

                case "LINKURL":
                case "LINK URL":
                    return(TemplateEngine.FormatString(this.LinkUrl, format ?? "RAW"));

                case "PAGERIMAGEURL":
                case "PAGER IMAGE URL":
                    return(TemplateEngine.FormatString(this.PagerImageUrl, format ?? "RAW"));

                case "SORTORDER":
                case "SORT ORDER":
                    return(this.SortOrder.ToString(format, CultureInfo.CurrentCulture));

                case "STARTDATE":
                case "START DATE":
                    return(this.StartDate.ToString(format, CultureInfo.CurrentCulture));

                case "IMAGEURL":
                case "IMAGE URL":
                    return(TemplateEngine.FormatString(this.ImageUrl, format ?? "RAW"));

                case "TITLE":
                    return(TemplateEngine.FormatString(this.Title, format ?? "HTML"));

                case "SLIDEID":
                case "SLIDE ID":
                    return(this.slideId.ToString(format, CultureInfo.CurrentCulture));

                case "INDEX":
                    if (this.itemIndex.HasValue)
                    {
                        return(this.itemIndex.Value.ToString(format, CultureInfo.InvariantCulture));
                    }

                    break;
                }
            }

            return(string.Empty);
        }