Beispiel #1
0
        public override bool Format(
            T value,
            FormatContext context)
        {
            using var _ = context.IncrementDepth();

            if (value is null)
            {
                HtmlFormatter.FormatAndStyleAsPlainText(Formatter.NullString, context);
                return(true);
            }

            return(_format(value, context));
        }
Beispiel #2
0
        /// <summary>
        /// Formats an object and writes it to the specified writer.
        /// </summary>
        /// <param name="obj">The object to be formatted.</param>
        /// <param name="context">The context for the current format operation.</param>
        /// <param name="mimeType">The mime type to format to.</param>
        public static void FormatTo(
            T obj,
            FormatContext context,
            string mimeType = PlainTextFormatter.MimeType)
        {
            if (obj is null)
            {
                var formatter = Formatter.GetPreferredFormatterFor(typeof(T), mimeType);
                formatter.Format(null, context);
                return;
            }

            using var _ = context.IncrementDepth();

            if (context.Depth <= Formatter.RecursionLimit)
            {
                var formatter = Formatter.GetPreferredFormatterFor(typeof(T), mimeType);
                formatter.Format(obj, context);
            }
            else
            {
                PlainTextFormatter <T> .Default.Format(obj, context);
            }
        }