Exemple #1
0
        public static void SerializeEnumClassUndefined()
        {
            EnumClass enumClass = new EnumClass()
            {
                StoreColor          = (StoreColor)1000,
                NullableStoreColor1 = (StoreColor)1000,
                NullableStoreColor2 = null
            };

            string json = JsonSerializer.Serialize(enumClass, new JsonSerializerOptions {
                WriteIndented = true
            });

            Assert.Equal(@"{
  ""StoreColor"": 1000,
  ""NullableStoreColor1"": 1000,
  ""NullableStoreColor2"": null
}".NormalizeLineEndings(), json);
        }
Exemple #2
0
        public static void SerializeFlagEnum()
        {
            EnumClass enumClass = new EnumClass()
            {
                StoreColor          = StoreColor.Red | StoreColor.White,
                NullableStoreColor1 = StoreColor.White & StoreColor.Yellow,
                NullableStoreColor2 = StoreColor.Red | StoreColor.White | StoreColor.Black
            };

            string json = JsonSerializer.Serialize(enumClass, new JsonSerializerOptions {
                WriteIndented = true
            });

            Assert.Equal(@"{
  ""StoreColor"": 10,
  ""NullableStoreColor1"": 0,
  ""NullableStoreColor2"": 11
}".NormalizeLineEndings(), json);
        }
        public static void SerializeEnumClass()
        {
            EnumClass enumClass = new EnumClass()
            {
                StoreColor          = StoreColor.Red,
                NullableStoreColor1 = StoreColor.White,
                NullableStoreColor2 = null
            };

            string json = JsonSerializer.ToString(enumClass, new JsonSerializerOptions {
                WriteIndented = true
            });

            Assert.Equal(@"{
  ""StoreColor"": 2,
  ""NullableStoreColor1"": 8,
  ""NullableStoreColor2"": null
}", json);
        }