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


C# TestObjects.Person类代码示例

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


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

示例1: JsonConvertSerializerSettings

    public void JsonConvertSerializerSettings()
    {
      Person person = new Person();
      person.BirthDate = new DateTime(2000, 11, 20, 23, 55, 44, DateTimeKind.Utc);
      person.LastModified = new DateTime(2000, 11, 20, 23, 55, 44, DateTimeKind.Utc);
      person.Name = "Name!";

      string json = JsonConvert.SerializeObject(person, Formatting.Indented, new JsonSerializerSettings
                                                               {
                                                                 ContractResolver = new CamelCasePropertyNamesContractResolver()
                                                               });

      Assert.AreEqual(@"{
  ""name"": ""Name!"",
  ""birthDate"": ""2000-11-20T23:55:44Z"",
  ""lastModified"": ""2000-11-20T23:55:44Z""
}", json);

      Person deserializedPerson = JsonConvert.DeserializeObject<Person>(json, new JsonSerializerSettings
                                                                        {
                                                                          ContractResolver = new CamelCasePropertyNamesContractResolver()
                                                                        });

      Assert.AreEqual(person.BirthDate, deserializedPerson.BirthDate);
      Assert.AreEqual(person.LastModified, deserializedPerson.LastModified);
      Assert.AreEqual(person.Name, deserializedPerson.Name);

      json = JsonConvert.SerializeObject(person, Formatting.Indented);
      Assert.AreEqual(@"{
  ""Name"": ""Name!"",
  ""BirthDate"": ""2000-11-20T23:55:44Z"",
  ""LastModified"": ""2000-11-20T23:55:44Z""
}", json);

    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:35,代码来源:CamelCasePropertyNamesContractResolverTests.cs

示例2: PopulatePerson

        public void PopulatePerson()
        {
            Person p = new Person();

            JsonConvert.PopulateObject(@"{""Name"":""James""}", p);

            Assert.AreEqual("James", p.Name);
        }
开发者ID:TheHunter,项目名称:Newtonsoft.Json,代码行数:8,代码来源:PopulateTests.cs

示例3: CreateGetWithBadObjectTarget

    public void CreateGetWithBadObjectTarget()
    {
      Person p = new Person();
      p.Name = "Hi";

      Func<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateGet<object>(typeof(Movie).GetProperty("Name"));

      setter(p);
    }
开发者ID:adrianhewitt,项目名称:to-Screenshot-Generator,代码行数:9,代码来源:DynamicReflectionDelegateFactoryTests.cs

示例4: CreateGetWithBadObjectTarget

    public void CreateGetWithBadObjectTarget()
    {
      ExceptionAssert.Throws<InvalidCastException>("Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.",
      () =>
      {
        Person p = new Person();
        p.Name = "Hi";

        Func<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateGet<object>(typeof(Movie).GetProperty("Name"));

        setter(p);
      });
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:13,代码来源:DynamicReflectionDelegateFactoryTests.cs

示例5: CreateSetWithBadObjectTarget

    public void CreateSetWithBadObjectTarget()
    {
      Person p = new Person();
      Movie m = new Movie();

      Action<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateSet<object>(typeof(Movie).GetProperty("Name"));

      setter(m, "Hi");

      Assert.AreEqual(m.Name, "Hi");

      setter(p, "Hi");
    }
开发者ID:adrianhewitt,项目名称:to-Screenshot-Generator,代码行数:13,代码来源:DynamicReflectionDelegateFactoryTests.cs

示例6: BlogCodeSample

        public void BlogCodeSample()
        {
            Person p = new Person
            {
                Name = "Keith",
                BirthDate = new DateTime(1980, 3, 8),
                LastModified = new DateTime(2009, 4, 12, 20, 44, 55),
            };

            string jsonText = JsonConvert.SerializeObject(p, new IsoDateTimeConverter());
            // {
            //   "Name": "Keith",
            //   "BirthDate": "1980-03-08T00:00:00",
            //   "LastModified": "2009-04-12T20:44:55"
            // }

            Assert.AreEqual(@"{""Name"":""Keith"",""BirthDate"":""1980-03-08T00:00:00"",""LastModified"":""2009-04-12T20:44:55""}", jsonText);
        }
开发者ID:b-bot-108,项目名称:brain-bot-111-b-bot-110-BND,代码行数:18,代码来源:IsoDateTimeConverterTests.cs

示例7: BlogCodeSample

    public void BlogCodeSample()
    {
      Person p = new Person
                   {
                     Name = "Keith",
                     BirthDate = new DateTime(1980, 3, 8),
                     LastModified = new DateTime(2009, 4, 12, 20, 44, 55),
                   };

      string jsonText = JsonConvert.SerializeObject(p, new IsoDateTimeConverter());
      // {
      //   "Name": "Keith",
      //   "BirthDate": "1980-03-08T00:00:00",
      //   "LastModified": "2009-04-12T20:44:55"
      // }

      Console.WriteLine(jsonText);

    }
开发者ID:Top-Cat,项目名称:SteamBot,代码行数:19,代码来源:IsoDateTimeConverterTests.cs

示例8: FromObjectInsideConverterWithCustomSerializer

    public void FromObjectInsideConverterWithCustomSerializer()
    {
      var p = new Person
      {
        Name = "Daniel Wertheim",
      };

      var settings = new JsonSerializerSettings
      {
        Converters = new List<JsonConverter> { new FooJsonConverter() },
        ContractResolver = new CamelCasePropertyNamesContractResolver()
      };

      var json = JsonConvert.SerializeObject(p, settings);

      Assert.AreEqual(@"{""foo"":""bar"",""name"":""Daniel Wertheim"",""birthDate"":""0001-01-01T00:00:00"",""lastModified"":""0001-01-01T00:00:00""}", json);
    }
开发者ID:Jessecar96,项目名称:Newtonsoft.Json,代码行数:17,代码来源:JObjectTests.cs

示例9: CreatePropertyGetter

        public void CreatePropertyGetter()
        {
            PropertyInfo namePropertyInfo = typeof(Person).GetProperty(nameof(Person.Name));

            Assert.IsNotNull(namePropertyInfo);

            var call = DynamicReflectionDelegateFactory.Instance.CreateGet<Person>(namePropertyInfo);

            Person p = new Person();
            p.Name = "Name!";

            object result = call(p);
            Assert.IsNotNull(result);

            Assert.AreEqual("Name!", (string)result);
        }
开发者ID:ChuangYang,项目名称:Newtonsoft.Json,代码行数:16,代码来源:DynamicReflectionDelegateFactoryTests.cs

示例10: CreateSetWithBadObjectTarget

        public void CreateSetWithBadObjectTarget()
        {
            ExceptionAssert.Throws<InvalidCastException>(() =>
            {
                Person p = new Person();
                Movie m = new Movie();

                Action<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateSet<object>(typeof(Movie).GetProperty("Name"));

                setter(m, "Hi");

                Assert.AreEqual(m.Name, "Hi");

                setter(p, "Hi");

                Assert.AreEqual(p.Name, "Hi");
            }, "Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.");
        }
开发者ID:ChuangYang,项目名称:Newtonsoft.Json,代码行数:18,代码来源:DynamicReflectionDelegateFactoryTests.cs

示例11: CreateSetWithBadObjectTarget

        public void CreateSetWithBadObjectTarget()
        {
            ExceptionAssert.Throws<InvalidCastException>(
                () => {
                    Person p = new Person();
                    Movie m = new Movie();

                    Action<object, object> setter = ExpressionReflectionDelegateFactory.Instance.CreateSet<object>(typeof(Movie).GetProperty("Name"));

                    setter(m, "Hi");

                    Assert.AreEqual(m.Name, "Hi");

                    setter(p, "Hi");

                    Assert.AreEqual(p.Name, "Hi");
                },
                new [] {
                    "Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.",
                    "Cannot cast from source type to destination type." // mono
                });
        }
开发者ID:Redth,项目名称:Newtonsoft.Json,代码行数:22,代码来源:ExpressionReflectionDelegateFactoryTests.cs

示例12: PersonPropertyClass

 public PersonPropertyClass()
 {
   Person = new WagePerson();
 }
开发者ID:VirtueMe,项目名称:ravendb,代码行数:4,代码来源:PersonPropertyClass.cs

示例13: CreateGetWithBadObjectTarget

        public void CreateGetWithBadObjectTarget()
        {
            ExceptionAssert.Throws<InvalidCastException>(
                () => {
                    Person p = new Person();
                    p.Name = "Hi";

                    Func<object, object> setter = ExpressionReflectionDelegateFactory.Instance.CreateGet<object>(TestReflectionUtils.GetProperty(typeof(Movie), "Name"));

                    setter(p);
                },
                new [] {
                    "Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.",
                    "Cannot cast from source type to destination type." // mono
                });
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:16,代码来源:ExpressionReflectionDelegateFactoryTests.cs

示例14: JsonConvertSerializerSettings

        public void JsonConvertSerializerSettings()
        {
            var person = new Person();
              person.BirthDate = new DateTime(2000, 11, 20, 23, 55, 44, DateTimeKind.Utc);
              person.LastModified = new DateTime(2000, 11, 20, 23, 55, 44, DateTimeKind.Utc);
              person.Name = "Name!";

              string json = ChasonSerializer.SerializeToString(person, new ChasonSerializerSettings()
                                                               {
                                                                   PropertyNameComparer = StringComparer.OrdinalIgnoreCase,
                                                                   OutputFormattedJson = true,
                                                                   OutputCamelCasePropertyNames = true,
                                                                   DateTimeFormat = ChasonSerializerSettings.JavascriptDateObjectDateTimeFormat
                                                               });

              json.Should().Be(@"{
              ""name"": ""Name!"",
              ""birthDate"": ""\/Date(974764544000)\/"",
              ""lastModified"": ""\/Date(974764544000)\/""
            }");

              Person deserializedPerson = ChasonSerializer.DeserializeFromString<Person>(json, new ChasonSerializerSettings
                                                                        {
                                                                            PropertyNameComparer = StringComparer.OrdinalIgnoreCase,
                                                                            OutputFormattedJson = true,
                                                                            OutputCamelCasePropertyNames = true,
                                                                            DateTimeFormat = ChasonSerializerSettings.JavascriptDateObjectDateTimeFormat
                                                                        });

              Assert.AreEqual(person.BirthDate, deserializedPerson.BirthDate);
              Assert.AreEqual(person.LastModified, deserializedPerson.LastModified);
              Assert.AreEqual(person.Name, deserializedPerson.Name);

              json = ChasonSerializer.SerializeToString(person, new ChasonSerializerSettings() { OutputFormattedJson = true });
              json.Should().Be(@"{
              ""Name"": ""Name!"",
              ""BirthDate"": ""\/Date(974764544000)\/"",
              ""LastModified"": ""\/Date(974764544000)\/""
            }");
        }
开发者ID:FlatlinerDOA,项目名称:Chason,代码行数:40,代码来源:CamelCasePropertyNamesContractResolverTests.cs


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