Example #1
0
        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="prop">The property.</param>
        /// <param name="isHtml">if set to <c>true</c> [is HTML].</param>
        /// <returns>System.String.</returns>
        private string GetValue(IDynamicObject item, PropertyInfo prop, bool isHtml)
        {
            if (!item.CanReadPropertyByName(prop.Name))
                return Encode(Constants.BlockedContent, isHtml);

            if (prop.Name == Constants.PaperclipsColumnName)
                return GetPaperclips(item, isHtml);

            var crossRefAttr = (CrossRefFieldAttribute)
                prop.GetCustomAttributes(typeof (CrossRefFieldAttribute), false).FirstOrDefault();

            if (crossRefAttr != null)
            {
                if (crossRefAttr.AllowMultiple)
                    return GetMultiCrossRefValue(item, prop, isHtml);

                return GetSingleCrossRefValue(item, prop, isHtml);
            }

            var reverseCrossRefAttr = (ReverseCrossRefFieldAttribute)
                                      prop.GetCustomAttributes(typeof (ReverseCrossRefFieldAttribute), false).FirstOrDefault();

            if (reverseCrossRefAttr != null)
            {
                if (reverseCrossRefAttr.DisplayMultiple)
                    return GetMultiReverseCrossRefValue(item, prop, isHtml);

                return GetReverseSingleCrossRefValue(item, prop, isHtml);
            }

            var dateTimeAttr =
                (DateTimeFormatAttribute)
                prop.GetCustomAttributes(typeof(DateTimeFormatAttribute), false).FirstOrDefault();

            if (dateTimeAttr != null)
                return GetDateTimeFieldValue(item, prop, dateTimeAttr, isHtml);

            var numericAttr =
                (NumericAttribute)
                prop.GetCustomAttributes(typeof(NumericAttribute), false).FirstOrDefault();

            if (numericAttr != null)
                return GetNumericFieldValue(item, prop, numericAttr, isHtml);

            var richTextAttr = prop.GetCustomAttributes(typeof(RichTextAttribute), false).FirstOrDefault();

            if (richTextAttr != null)
                return GetRichTextFieldValue(item, prop, isHtml);

            var fileAttribute = prop.GetCustomAttribute<FileProcessAttribute>();
            if (fileAttribute != null)
                return GetFileValue(item, prop, isHtml);

            return GetGenericFieldValue(item, prop, isHtml);
        }