public static LocalizedHtmlString GetTitleOrDefault(this IActivity activity, Func <LocalizedHtmlString> defaultTitle) { var title = activity.As <ActivityMetadata>().Title; // A string used in LocalizedHtmlString won't be encoded so it needs to be pre-encoded. // Passing the title as an argument so it uses the HtmlEncoder when rendered // Another options would be to use new LocalizedHtmlString(Html.Encode(title)) but it's not available in the current context return(!string.IsNullOrEmpty(title) ? new LocalizedHtmlString(nameof(ActivityExtensions.GetTitleOrDefault), "{0}", false, title) : defaultTitle()); }
public static LocalizedHtmlString GetTitleOrDefault(this IActivity activity, Func <LocalizedHtmlString> defaultTitle) { var title = activity.As <ActivityMetadata>().Title; return(!string.IsNullOrEmpty(title) ? new LocalizedHtmlString(title, title) : defaultTitle()); }