Esempio n. 1
0
 public static void Register(
     Func <T, string> formatter,
     string mimeType    = PlainTextFormatter.MimeType,
     bool addToDefaults = false)
 {
     Formatter.Register(formatter, mimeType, addToDefaults);
 }
Esempio n. 2
0
 public static void Register(
     Action <T, TextWriter> formatter,
     string mimeType    = PlainTextFormatter.MimeType,
     bool addToDefaults = false)
 {
     Formatter.Register(formatter, mimeType, addToDefaults);
 }
Esempio n. 3
0
        public static void Register(
            Action <T, TextWriter> formatter,
            string mimeType = PlainTextFormatter.MimeType)
        {
            if (formatter == null)
            {
                throw new ArgumentNullException(nameof(formatter));
            }

            if (typeof(T) == typeof(Type))
            {
                // special treatment is needed since typeof(Type) == System.RuntimeType, which is not public
                // ReSharper disable once PossibleMistakenCallToGetType.2
                Formatter.Register(
                    typeof(Type).GetType(),
                    (o, writer) => formatter((T)o, writer),
                    mimeType);
            }
            else if (!typeof(T).CanBeInstantiated())
            {
                Formatter.RegisterLazilyForConcreteTypesOf(
                    typeof(T),
                    (o, writer) => formatter((T)o, writer), mimeType);
                return;
            }

            Formatter.TypeFormatters[(typeof(T), mimeType)] = new AnonymousTypeFormatter <T>(formatter, mimeType);
Esempio n. 4
0
        public static void SetupDefaultMimeTypes()
        {
            Formatter <LaTeXString> .Register((laTeX, writer) => writer.Write(laTeX.ToString()), "text/latex");

            Formatter <MathString> .Register((math, writer) => writer.Write(math.ToString()), "text/latex");

            Formatter.SetPreferredMimeTypeFor(typeof(LaTeXString), "text/latex");
            Formatter.SetPreferredMimeTypeFor(typeof(MathString), "text/latex");

            Formatter.SetPreferredMimeTypeFor(typeof(string), PlainTextFormatter.MimeType);

            Formatter.SetDefaultMimeType(HtmlFormatter.MimeType);
        }
Esempio n. 5
0
        public static void SetUpFormatters()
        {
            Formatter.DefaultMimeType = HtmlFormatter.MimeType;
            Formatter.SetPreferredMimeTypeFor(typeof(string), PlainTextFormatter.MimeType);
            Formatter.SetPreferredMimeTypeFor(typeof(ScriptContent), HtmlFormatter.MimeType);

            Formatter.Register <ScriptContent>((script, writer) =>
            {
                IHtmlContent content =
                    PocketViewTags.script[type: "text/javascript"](script.ScriptValue.ToHtmlContent());
                content.WriteTo(writer, HtmlEncoder.Default);
            }, HtmlFormatter.MimeType);
        }
Esempio n. 6
0
 /// <summary>
 /// Registers a formatter to be used when formatting instances of type <typeparamref name="T" />.
 /// </summary>
 /// <param name="formatter">The formatter.</param>
 public static void Register(
     Func <T, string> formatter,
     string mimeType = PlainTextFormatter.MimeType)
 {
     Formatter.Register(new AnonymousTypeFormatter <T>((obj, writer) => writer.Write(formatter((T)obj)), mimeType));
 }
Esempio n. 7
0
 public static void Register(
     Action <T, TextWriter> formatter,
     string mimeType = PlainTextFormatter.MimeType)
 {
     Formatter.Register(new AnonymousTypeFormatter <T>(formatter, mimeType));
 }