/// <summary> /// Determines whether a given <see cref="RichText"/> instance is <c>null</c> or empty. /// </summary> /// <param name="richText">The <see cref="RichText"/> instance to test.</param> /// <returns><c>true</c> if <paramref name="richText"/> is <c>null</c> or empty.</returns> /// <remarks>This is a cheaper alternative to <see cref="string.IsNullOrEmpty"/> on a <see cref="RichText"/> instance using implicit string cast.</remarks> public static bool IsNullOrEmpty(RichText richText) { return (richText == null) || richText.IsEmpty(); }
/// <summary> /// Renders a given <see cref="RichText"/> instance as HTML. /// </summary> /// <param name="htmlHelper">The HtmlHelper instance on which the extension method operates.</param> /// <param name="richText">The <see cref="RichText"/> instance to render. If the rich text contains Entity Models, those will be rendered using applicable Views.</param> /// <returns>The rendered HTML.</returns> public static MvcHtmlString DxaRichText(this HtmlHelper htmlHelper, RichText richText) { if (richText == null) { return MvcHtmlString.Empty; } StringBuilder htmlBuilder = new StringBuilder(); foreach (IRichTextFragment richTextFragment in richText.Fragments) { EntityModel entityModel = richTextFragment as EntityModel; string htmlFragment = (entityModel == null) ? richTextFragment.ToHtml() : htmlHelper.DxaEntity(entityModel).ToString(); htmlBuilder.Append(htmlFragment); } return new MvcHtmlString(htmlBuilder.ToString()); }
/// <summary> /// Determines whether a given <see cref="RichText"/> instance is <c>null</c> or empty. /// </summary> /// <param name="richText">The <see cref="RichText"/> instance to test.</param> /// <returns><c>true</c> if <paramref name="richText"/> is <c>null</c> or empty.</returns> /// <remarks>This is a cheaper alternative to <see cref="string.IsNullOrEmpty"/> on a <see cref="RichText"/> instance using implicit string cast.</remarks> public static bool IsNullOrEmpty(RichText richText) { return((richText == null) || richText.IsEmpty()); }