Ejemplo n.º 1
0
        public static void ReadSimpleStruct()
        {
            byte[]           utf8       = Encoding.UTF8.GetBytes(SimpleTestStruct.s_json);
            var              reader     = new Utf8JsonReader(utf8, isFinalBlock: true, state: default);
            SimpleTestStruct testStruct = JsonSerializer.ReadValue <SimpleTestStruct>(ref reader);

            testStruct.Verify();

            reader = new Utf8JsonReader(utf8, isFinalBlock: true, state: default);
            object obj = JsonSerializer.ReadValue(ref reader, typeof(SimpleTestStruct));

            ((SimpleTestStruct)obj).Verify();
        }
Ejemplo n.º 2
0
        public static void ReadSimpleTestStructWithSimpleTestClass()
        {
            SimpleTestStruct testObject = new SimpleTestStruct();

            testObject.Initialize();
            testObject.MySimpleTestClass = new SimpleTestClass  {
                MyString = "Hello", MyDouble = 3.14
            };

            string           json         = JsonSerializer.ToString(testObject);
            SimpleTestStruct parsedObject = JsonSerializer.Parse <SimpleTestStruct>(json);

            parsedObject.Verify();
        }
Ejemplo n.º 3
0
        public static void ReadSimpleTestStructWithSimpleTestClass()
        {
            SimpleTestStruct testObject = new SimpleTestStruct();

            testObject.Initialize();
            testObject.MySimpleTestClass = new SimpleTestClass {
                MyString = "Hello", MyDouble = 3.14
            };

            string           json         = JsonSerializer.Serialize(testObject);
            SimpleTestStruct parsedObject = JsonSerializer.Deserialize <SimpleTestStruct>(json);

            parsedObject.Verify();
            Assert.Equal(3.14, parsedObject.MySimpleTestClass.MyDouble);
            Assert.Equal("Hello", parsedObject.MySimpleTestClass.MyString);
        }
Ejemplo n.º 4
0
        public static void ReadSimpleStruct()
        {
            SimpleTestStruct obj = JsonSerializer.Deserialize <SimpleTestStruct>(SimpleTestStruct.s_json);

            obj.Verify();
        }