当前位置: 首页>>代码示例>>C#>>正文


C# Serialization.MemoryTraceWriter类代码示例

本文整理汇总了C#中Newtonsoft.Json.Serialization.MemoryTraceWriter的典型用法代码示例。如果您正苦于以下问题:C# MemoryTraceWriter类的具体用法?C# MemoryTraceWriter怎么用?C# MemoryTraceWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MemoryTraceWriter类属于Newtonsoft.Json.Serialization命名空间,在下文中一共展示了MemoryTraceWriter类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Example

        public void Example()
        {
            #region Usage
            string json = @"{
              'FullName': 'Dan Deleted',
              'Deleted': true,
              'DeletedDate': '2013-01-20T00:00:00'
            }";

            MemoryTraceWriter traceWriter = new MemoryTraceWriter();

            Account account = JsonConvert.DeserializeObject<Account>(json, new JsonSerializerSettings
            {
                TraceWriter = traceWriter
            });

            Console.WriteLine(traceWriter.ToString());
            // 2013-01-21T01:36:24.422 Info Started deserializing Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path 'FullName', line 2, position 20.
            // 2013-01-21T01:36:24.442 Verbose Could not find member 'DeletedDate' on Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path 'DeletedDate', line 4, position 23.
            // 2013-01-21T01:36:24.447 Info Finished deserializing Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path '', line 5, position 8.
            // 2013-01-21T01:36:24.450 Verbose Deserialized JSON: 
            // {
            //   "FullName": "Dan Deleted",
            //   "Deleted": true,
            //   "DeletedDate": "2013-01-20T00:00:00"
            // }
            #endregion

            Assert.AreEqual(4, traceWriter.GetTraceMessages().Count());
        }
开发者ID:b-bot-110,项目名称:Newtonsoft.Json,代码行数:30,代码来源:TraceWriter.cs

示例2: MemoryTraceWriterTest

    public void MemoryTraceWriterTest()
    {
      Staff staff = new Staff();
      staff.Name = "Arnie Admin";
      staff.Roles = new List<string> {"Administrator"};
      staff.StartDate = DateTime.Now;

      ITraceWriter traceWriter = new MemoryTraceWriter();

      JsonConvert.SerializeObject(
        staff,
        new JsonSerializerSettings {TraceWriter = traceWriter, Converters = {new JavaScriptDateTimeConverter()}});

      Console.WriteLine(traceWriter);
      // 2012-11-11T12:08:42.761 Info Started serializing Newtonsoft.Json.Tests.Serialization.Staff. Path ''.
      // 2012-11-11T12:08:42.785 Info Started serializing System.DateTime with converter Newtonsoft.Json.Converters.JavaScriptDateTimeConverter. Path 'StartDate'.
      // 2012-11-11T12:08:42.791 Info Finished serializing System.DateTime with converter Newtonsoft.Json.Converters.JavaScriptDateTimeConverter. Path 'StartDate'.
      // 2012-11-11T12:08:42.797 Info Started serializing System.Collections.Generic.List`1[System.String]. Path 'Roles'.
      // 2012-11-11T12:08:42.798 Info Finished serializing System.Collections.Generic.List`1[System.String]. Path 'Roles'.
      // 2012-11-11T12:08:42.799 Info Finished serializing Newtonsoft.Json.Tests.Serialization.Staff. Path ''.

      MemoryTraceWriter memoryTraceWriter = (MemoryTraceWriter)traceWriter;

      Assert.AreEqual(743, memoryTraceWriter.ToString().Length);
      Assert.AreEqual(6, memoryTraceWriter.GetTraceMessages().Count());
    }
开发者ID:925coder,项目名称:ravendb,代码行数:26,代码来源:TraceWriterTests.cs

示例3: Wrapped

    public void Wrapped()
    {
      MockMessageBroker broker = new MockMessageBroker();
      MockExecutionTimer timer = new MockExecutionTimer();

      MemoryTraceWriter innerWriter = new MemoryTraceWriter();

      GlimpseTraceWriter writer = new GlimpseTraceWriter(broker, () => timer, innerWriter);
      writer.Trace(TraceLevel.Verbose, "Random text", null);
      writer.Trace(TraceLevel.Error, "More random text", null);
      Assert.AreEqual(2, writer.TraceMessages.Count);

      Assert.AreEqual(2, innerWriter.GetTraceMessages().Count());

      Assert.AreEqual("Verbose Random text", innerWriter.GetTraceMessages().ElementAt(0).Substring(24));
      Assert.AreEqual("Error More random text", innerWriter.GetTraceMessages().ElementAt(1).Substring(24));

      innerWriter.LevelFilter = TraceLevel.Warning;
      writer.Trace(TraceLevel.Verbose, "Random text", null);
      writer.Trace(TraceLevel.Warning, "More random text", null);
      writer.Trace(TraceLevel.Error, "More random text", null);
      Assert.AreEqual(4, innerWriter.GetTraceMessages().Count());

      Assert.AreEqual(TraceLevel.Verbose, writer.LevelFilter);
    }
开发者ID:modulexcite,项目名称:Newtonsoft.Json.Glimpse,代码行数:25,代码来源:GlimpseTraceWriterTests.cs

示例4: WriteJRaw

        public void WriteJRaw()
        {
            ITraceWriter traceWriter = new MemoryTraceWriter();

            JRaw settings = new JRaw("$('#element')");
            string json = JsonConvert.SerializeObject(settings, new JsonSerializerSettings
            {
                TraceWriter = traceWriter
            });

            Assert.AreEqual("$('#element')", json);

            Assert.IsTrue(traceWriter.ToString().EndsWith("Verbose Serialized JSON: " + Environment.NewLine + "$('#element')", StringComparison.Ordinal));
        }
开发者ID:ruisebastiao,项目名称:Newtonsoft.Json,代码行数:14,代码来源:TraceWriterTests.cs

示例5: dumpjson

        public void dumpjson()
        {
            MemoryTraceWriter _traceWriter = new MemoryTraceWriter();
            _serializerSettings = new JsonSerializerSettings()
            {
                Error = (sender, args) => Console.Write(args.ErrorContext.Error),
                Formatting = Formatting.Indented,
                TraceWriter = _traceWriter,
            };

            if (lmat == null)
                return;
            String json = JsonConvert.SerializeObject(lmat, _serializerSettings);

            using (var sw = new StreamWriter("MatiereBijoux.json", false))
                sw.Write(json);
        }
开发者ID:Jupotter,项目名称:Terre-Natale-Calculateur,代码行数:17,代码来源:Bijouxmanager.cs

示例6: MemoryTraceWriterSerializeTest

        public void MemoryTraceWriterSerializeTest()
        {
            Staff staff = new Staff();
            staff.Name = "Arnie Admin";
            staff.Roles = new List<string> { "Administrator" };
            staff.StartDate = new DateTime(2000, 12, 12, 12, 12, 12, DateTimeKind.Utc);

            ITraceWriter traceWriter = new MemoryTraceWriter();

            JsonConvert.SerializeObject(
                staff,
                new JsonSerializerSettings { TraceWriter = traceWriter, Converters = { new JavaScriptDateTimeConverter() } });

            Console.WriteLine(traceWriter);
            // 2012-11-11T12:08:42.761 Info Started serializing Newtonsoft.Json.Tests.Serialization.Staff. Path ''.
            // 2012-11-11T12:08:42.785 Info Started serializing System.DateTime with converter Newtonsoft.Json.Converters.JavaScriptDateTimeConverter. Path 'StartDate'.
            // 2012-11-11T12:08:42.791 Info Finished serializing System.DateTime with converter Newtonsoft.Json.Converters.JavaScriptDateTimeConverter. Path 'StartDate'.
            // 2012-11-11T12:08:42.797 Info Started serializing System.Collections.Generic.List`1[System.String]. Path 'Roles'.
            // 2012-11-11T12:08:42.798 Info Finished serializing System.Collections.Generic.List`1[System.String]. Path 'Roles'.
            // 2012-11-11T12:08:42.799 Info Finished serializing Newtonsoft.Json.Tests.Serialization.Staff. Path ''.

            MemoryTraceWriter memoryTraceWriter = (MemoryTraceWriter)traceWriter;
            string output = memoryTraceWriter.ToString();

            Assert.AreEqual(916, output.Length);
            Assert.AreEqual(7, memoryTraceWriter.GetTraceMessages().Count());

            string json = @"Serialized JSON: 
{
  ""Name"": ""Arnie Admin"",
  ""StartDate"": new Date(
    976623132000
  ),
  ""Roles"": [
    ""Administrator""
  ]
}";

            json = StringAssert.Normalize(json);
            output = StringAssert.Normalize(output);

            Assert.IsTrue(output.Contains(json));
        }
开发者ID:andersonb,项目名称:Newtonsoft.Json,代码行数:43,代码来源:TraceWriterTests.cs

示例7: MemoryTraceWriterTest

    public void MemoryTraceWriterTest()
    {
      #region MemoryTraceWriterExample
      Staff staff = new Staff();
      staff.Name = "Arnie Admin";
      staff.Roles = new List<string> { "Administrator" };
      staff.StartDate = new DateTime(2000, 12, 12, 12, 12, 12, DateTimeKind.Utc);

      ITraceWriter traceWriter = new MemoryTraceWriter();

      JsonConvert.SerializeObject(
        staff,
        new JsonSerializerSettings { TraceWriter = traceWriter, Converters = { new JavaScriptDateTimeConverter() } });

      Console.WriteLine(traceWriter);
      // 2012-11-11T12:08:42.761 Info Started serializing Newtonsoft.Json.Tests.Serialization.Staff. Path ''.
      // 2012-11-11T12:08:42.785 Info Started serializing System.DateTime with converter Newtonsoft.Json.Converters.JavaScriptDateTimeConverter. Path 'StartDate'.
      // 2012-11-11T12:08:42.791 Info Finished serializing System.DateTime with converter Newtonsoft.Json.Converters.JavaScriptDateTimeConverter. Path 'StartDate'.
      // 2012-11-11T12:08:42.797 Info Started serializing System.Collections.Generic.List`1[System.String]. Path 'Roles'.
      // 2012-11-11T12:08:42.798 Info Finished serializing System.Collections.Generic.List`1[System.String]. Path 'Roles'.
      // 2012-11-11T12:08:42.799 Info Finished serializing Newtonsoft.Json.Tests.Serialization.Staff. Path ''.
      // 2013-05-18T21:38:11.255 Verbose Serialized JSON: 
      // {
      //   "Name": "Arnie Admin",
      //   "StartDate": new Date(
      //     976623132000
      //   ),
      //   "Roles": [
      //     "Administrator"
      //   ]
      // }
      #endregion

      MemoryTraceWriter memoryTraceWriter = (MemoryTraceWriter)traceWriter;

      Assert.AreEqual(916, memoryTraceWriter.ToString().Length);
      Assert.AreEqual(7, memoryTraceWriter.GetTraceMessages().Count());
    }
开发者ID:PrototypeAlpha,项目名称:LiveSplit,代码行数:38,代码来源:TraceWriterTests.cs

示例8: MemoryTraceWriterLimitTest

        public void MemoryTraceWriterLimitTest()
        {
            MemoryTraceWriter traceWriter = new MemoryTraceWriter();

            for (int i = 0; i < 1005; i++)
            {
                traceWriter.Trace(TraceLevel.Verbose, (i + 1).ToString(CultureInfo.InvariantCulture), null);
            }

            IList<string> traceMessages = traceWriter.GetTraceMessages().ToList();

            Assert.AreEqual(1000, traceMessages.Count);

            Assert.IsTrue(traceMessages.First().EndsWith(" 6"));
            Assert.IsTrue(traceMessages.Last().EndsWith(" 1005"));
        }
开发者ID:SeanmanX,项目名称:opandroid,代码行数:16,代码来源:TraceWriterTests.cs

示例9: MemoryTraceWriterDeserializeTest

        public void MemoryTraceWriterDeserializeTest()
        {
            string json = @"{
  ""Name"": ""Arnie Admin"",
  ""StartDate"": new Date(
    976623132000
  ),
  ""Roles"": [
    ""Administrator""
  ]
}";

            Staff staff = new Staff();
            staff.Name = "Arnie Admin";
            staff.Roles = new List<string> { "Administrator" };
            staff.StartDate = new DateTime(2000, 12, 12, 12, 12, 12, DateTimeKind.Utc);

            ITraceWriter traceWriter = new MemoryTraceWriter();

            JsonConvert.DeserializeObject<Staff>(
                json,
                new JsonSerializerSettings
                {
                    TraceWriter = traceWriter,
                    Converters = { new JavaScriptDateTimeConverter() },
                    SpecialPropertyHandling = SpecialPropertyHandling.Default
                });

            Console.WriteLine(traceWriter);
            // 2012-11-11T12:08:42.761 Info Started serializing Newtonsoft.Json.Tests.Serialization.Staff. Path ''.
            // 2012-11-11T12:08:42.785 Info Started serializing System.DateTime with converter Newtonsoft.Json.Converters.JavaScriptDateTimeConverter. Path 'StartDate'.
            // 2012-11-11T12:08:42.791 Info Finished serializing System.DateTime with converter Newtonsoft.Json.Converters.JavaScriptDateTimeConverter. Path 'StartDate'.
            // 2012-11-11T12:08:42.797 Info Started serializing System.Collections.Generic.List`1[System.String]. Path 'Roles'.
            // 2012-11-11T12:08:42.798 Info Finished serializing System.Collections.Generic.List`1[System.String]. Path 'Roles'.
            // 2012-11-11T12:08:42.799 Info Finished serializing Newtonsoft.Json.Tests.Serialization.Staff. Path ''.
            // 2013-05-19T00:07:24.360 Verbose Deserialized JSON: 
            // {
            //   "Name": "Arnie Admin",
            //   "StartDate": new Date(
            //     976623132000
            //   ),
            //   "Roles": [
            //     "Administrator"
            //   ]
            // }

            MemoryTraceWriter memoryTraceWriter = (MemoryTraceWriter)traceWriter;
            string output = memoryTraceWriter.ToString();

            Assert.AreEqual(1059, output.Length);
            Assert.AreEqual(7, memoryTraceWriter.GetTraceMessages().Count());

            Assert.IsTrue(output.Contains(json));
        }
开发者ID:SeanmanX,项目名称:opandroid,代码行数:54,代码来源:TraceWriterTests.cs

示例10: Serialize

        private string Serialize(Foo1 f)
        {
            //Code copied from JsonConvert.SerializeObject(), with addition of trace writing
            JsonSerializer jsonSerializer = JsonSerializer.CreateDefault();
            var traceWriter = new MemoryTraceWriter();
            jsonSerializer.TraceWriter = traceWriter;

            StringBuilder sb = new StringBuilder(256);
            StringWriter sw = new StringWriter(sb, CultureInfo.InvariantCulture);
            using (JsonTextWriter jsonWriter = new JsonTextWriter(sw))
            {
                jsonWriter.Formatting = Formatting.None;
                jsonSerializer.Serialize(jsonWriter, f, typeof(Foo1));
            }

            return sw.ToString();
        }
开发者ID:b-bot-108,项目名称:brain-bot-111-b-bot-110-BND,代码行数:17,代码来源:ShouldSerializeTests.cs

示例11: SerializationBasics

        public void SerializationBasics()
        {
            IList<string> roles = new List<string>
            {
                "User",
                "Admin"
            };

            MemoryTraceWriter traceWriter = new MemoryTraceWriter();

            string j = JsonConvert.SerializeObject(roles, new JsonSerializerSettings
            {
                Formatting = Formatting.Indented,
                TraceWriter = traceWriter
            });

            string trace = traceWriter.ToString();
            // Started serializing System.Collections.Generic.List`1[System.String].
            // Finished serializing System.Collections.Generic.List`1[System.String].
            // 2014-05-13T13:41:53.706 Verbose Serialized JSON: 
            // [
            //   "User",
            //   "Admin"
            // ]

            Console.WriteLine(trace);
        }
开发者ID:andersonb,项目名称:Newtonsoft.Json,代码行数:27,代码来源:DemoTests.cs

示例12: WriteJRawInArray

        public void WriteJRawInArray()
        {
            ITraceWriter traceWriter = new MemoryTraceWriter();

            List<JRaw> raws = new List<JRaw>
            {
                new JRaw("$('#element')"),
                new JRaw("$('#element')"),
                new JRaw("$('#element')")
            };

            string json = JsonConvert.SerializeObject(raws, new JsonSerializerSettings
            {
                TraceWriter = traceWriter,
                Formatting = Formatting.Indented
            });

            StringAssert.AreEqual(@"[
  $('#element'),
  $('#element'),
  $('#element')
]", json);

            Assert.IsTrue(traceWriter.ToString().EndsWith(@"Verbose Serialized JSON: 
[
  $('#element'),
  $('#element'),
  $('#element')
]", StringComparison.Ordinal));
        }
开发者ID:ruisebastiao,项目名称:Newtonsoft.Json,代码行数:30,代码来源:TraceWriterTests.cs

示例13: ShouldDeserialize_False

        public void ShouldDeserialize_False()
        {
            string json = @"{'HasName':false,'Name':'Name!'}";

            MemoryTraceWriter traceWriter = new MemoryTraceWriter();
            ShouldDeserializeTestClass c = JsonConvert.DeserializeObject<ShouldDeserializeTestClass>(json, new JsonSerializerSettings
            {
                ContractResolver = ShouldDeserializeContractResolver.Instance,
                TraceWriter = traceWriter
            });

            Assert.AreEqual(1, c.ExtensionData.Count);
            Assert.AreEqual("Name!", (string)c.ExtensionData["Name"]);
            Assert.AreEqual(false, c.HasName);
            Assert.AreEqual(null, c.Name);

            Assert.IsTrue(traceWriter.GetTraceMessages().Any(m => m.EndsWith("Verbose ShouldDeserialize result for property 'Name' on Newtonsoft.Json.Tests.Serialization.ShouldDeserializeTestClass: False. Path 'Name'.")));
        }
开发者ID:veblush,项目名称:Newtonsoft.Json,代码行数:18,代码来源:ShouldSerializeTests.cs

示例14: ParseEntry

 private JobLogEntry ParseEntry(string line)
 {
     var writer = new MemoryTraceWriter();
     var old = _serializerSettings.TraceWriter;
     _serializerSettings.TraceWriter = writer;
     var result = JsonConvert.DeserializeObject<JobLogEntry>(line.Trim(), _serializerSettings);
     _serializerSettings.TraceWriter = old;
     foreach (var message in writer.GetTraceMessages())
     {
         Console.WriteLine(message);
     }
     return result;
 }
开发者ID:JetBrains,项目名称:NuGetOperations,代码行数:13,代码来源:JobLog.cs


注:本文中的Newtonsoft.Json.Serialization.MemoryTraceWriter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。