示例#1
0
        public void Serialize_Dict_With_Nulls()
        {
            var ser = new HtmlSerializerRegistry();

            ser.Add(o => o is IDictionary <string, object>, o =>
            {
                // try
                {
                    return(new GenDictSerializer().Serialize(o, 3, ser));
                }
                // catch (Exception e)
                // {
                // return new Span("ERROR").ToArray();
                // }
            });
            HtmlSerializerRegistry.AddDefaults(ser);
            ser.Serialize(null, 3, ser);


            IDictionary <string, object> toSer = new Dictionary <string, object>
            {
                { "key1", "val1" },
                { "key2", null },
                {
                    "key3", new Dictionary <string, object>
                    {
                        { "key4", null }
                    }
                }
            };

            // var elements = ser.Serialize(toSer, 3, ser);
        }
示例#2
0
        public void Serialize_DateTime()
        {
            var ser = HtmlSerializerRegistry.AddDefaults(new HtmlSerializerRegistry());

            var toSer = new SamplePoco
            {
                DateProp = DateTime.Now,
            };

            var elements = ser.Serialize(toSer, 3);
        }
示例#3
0
        public override async Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
        {
            var ser = new HtmlSerializerRegistry();
            var sp  = context.HttpContext.RequestServices;

            this._connectionProvider = sp.GetRequiredService <IDbConnectionProvider>();
            var creator = new ItemSerializer(sp.GetRequiredService <IDbInspector>(), sp.GetRequiredService <ILinkManager>());

            ser.Add(o => o is IDictionary <string, object>, o => creator.Serialize((IDictionary <string, object>)o, 3, ser));
            HtmlSerializerRegistry.AddDefaults(ser);
            var htmlElements = ser.Serialize(context.Object, 2, ser);

            var res = MakeCompleteDocument(context, htmlElements);
            await context.HttpContext.Response.WriteAsync(res.ToHtml());
        }
示例#4
0
        public void Serializing_WithIncludeType_ShouldIncludeType()
        {
            // Arrange
            var ser = HtmlSerializerRegistry.AddDefaults(new HtmlSerializerRegistry());

            // Act
            var elements = ser.Serialize(new SamplePoco
            {
                StringProp = "stringval",
            }, 3, ser).ToArray();

            // Assert
            AreEqual(1, elements.Length);
            AreEqual("SamplePoco", elements[0].Subs[1].Text);
        }
示例#5
0
        public void Serializing_Array_ShouldBeUlWithLiWithDl()
        {
            // Arrange
            var ser = HtmlSerializerRegistry.AddDefaults(new HtmlSerializerRegistry());

            // Act
            var elements = ser.Serialize(new[]
            {
                new SamplePoco
                {
                    StringProp = "stringval",
                }
            }, 3, ser).ToArray();

            // Assert
            AreEqual("ul", elements[0].Tag);
            AreEqual("li", elements[0].Subs[0].Tag);
            AreEqual("dl", elements[0].Subs[0].Subs[0].Tag);
        }