當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。