Пример #1
0
        /// <summary>
        /// Formats an object and writes it to the specified writer.
        /// </summary>
        /// <param name="obj">The object to be formatted.</param>
        /// <param name="writer">The writer.</param>
        /// <param name="mimeType">The mime type to format to.</param>
        public static void FormatTo(
            FormatContext context,
            T obj,
            TextWriter writer,
            string mimeType = PlainTextFormatter.MimeType)
        {
            if (obj == null)
            {
                var formatter = Formatter.GetPreferredFormatterFor(typeof(T), mimeType);
                formatter.Format(context, null, writer);
                return;
            }

            using var _ = Formatter.RecursionCounter.Enter();

            // find a formatter for the object type, and possibly register one on the fly
            if (Formatter.RecursionCounter.Depth <= Formatter.RecursionLimit)
            {
                var formatter = Formatter.GetPreferredFormatterFor(typeof(T), mimeType);
                formatter.Format(context, obj, writer);
            }
            else
            {
                PlainTextFormatter <T> .Default.Format(context, obj, writer);
            }
        }
        public override bool Format(FormatContext context, T instance, TextWriter writer)
        {
            var json = JsonConvert.SerializeObject(instance, JsonFormatter.SerializerSettings);

            writer.Write(json);
            return(true);
        }
Пример #3
0
        internal static void FormatObjectAsPlainText(FormatContext context, object value, TextWriter writer)
        {
            using var swriter = Formatter.CreateWriter();
            Formatter.FormatTo(value, context, swriter, PlainTextFormatter.MimeType);
            var text = swriter.ToString();

            FormatStringAsPlainText(text, writer);
        }
Пример #4
0
        internal static void FormatAndStyleAsPlainText(
            object text,
            FormatContext context)
        {
            PocketView tag = div(text.ToDisplayString(PlainTextFormatter.MimeType));

            tag.HtmlAttributes["class"] = "dni-plaintext";
            tag.WriteTo(context);
        }
Пример #5
0
        public override bool Format(T value, FormatContext context)
        {
            if (value is null)
            {
                context.Writer.Write(Formatter.NullString);
                return(true);
            }

            return(_format(value, context));
        }
        public override bool Format(FormatContext context, T value, TextWriter writer)
        {
            if (value is null)
            {
                writer.Write(Formatter.NullString);
                return(true);
            }

            return(_format(context, value, writer));
        }
Пример #7
0
        public override bool Format(FormatContext context, T value, TextWriter writer)
        {
            if (value is null)
            {
                HtmlFormatter.FormatStringAsPlainText(Formatter.NullString, writer);
                return(true);
            }

            return(_format(context, value, writer));
        }
Пример #8
0
        public override bool Format(
            T value,
            FormatContext context)
        {
            if (value is null)
            {
                HtmlFormatter.FormatAndStyleAsPlainText(Formatter.NullString, context);
                return(true);
            }

            return(_format(value, context));
        }
Пример #9
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));
        }
Пример #10
0
            private void WriteCss(FormatContext context)
            {
                var writer = context.Writer;

                writer.WriteLine();

                foreach (var selectorAndProps in _css)
                {
                    writer.Write(selectorAndProps.Key);
                    writer.WriteLine(" {");

                    foreach (var prop in selectorAndProps.Value)
                    {
                        writer.WriteLine($"  {prop.property}: {prop.value};");
                    }

                    writer.WriteLine("}");
                }
            }
Пример #11
0
        /// <summary>
        /// Formats an object and writes it to the specified writer.
        /// </summary>
        /// <param name="obj">The object to be formatted.</param>
        /// <param name="writer">The writer.</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 _ = Formatter.RecursionCounter.Enter();

            if (Formatter.RecursionCounter.Depth <= Formatter.RecursionLimit)
            {
                var formatter = Formatter.GetPreferredFormatterFor(typeof(T), mimeType);
                formatter.Format(obj, context);
            }
            else
            {
                PlainTextFormatter <T> .Default.Format(obj, context);
            }
        }
Пример #12
0
 /// <summary>Create an object suitable for delayed expansion to HTML</summary>
 public static object embed(object obj, FormatContext context)
 {
     return(new HtmlFormatter.EmbeddedFormat(context, obj));
 }
Пример #13
0
 bool ITypeFormatter.Format(FormatContext context, object instance, TextWriter writer)
 {
     return(Format(context, (T)instance, writer));
 }
Пример #14
0
 public abstract bool Format(FormatContext context, T value, TextWriter writer);
Пример #15
0
 public override bool Format(T instance, FormatContext context)
 {
     return(_format(instance, context));
 }
Пример #16
0
 public override bool Format(FormatContext context, T instance, TextWriter writer)
 {
     return(_format(context, instance, writer));
 }
Пример #17
0
 bool ITypeFormatter.Format(object instance, FormatContext context)
 {
     return(Format((T)instance, context));
 }
Пример #18
0
 public abstract bool Format(T value, FormatContext context);
 public override bool Format(T value, FormatContext context)
 {
     return(_format(value, context));
 }
Пример #20
0
 internal EmbeddedFormat(FormatContext context, object instance)
 {
     Object = instance;  Context = context;
 }
Пример #21
0
 public override bool Format(FormatContext context, T value, TextWriter writer)
 {
     return(_format(context, value, writer));
 }