コード例 #1
0
        [InlineData(13, "A16249640D")] // { "Id": 13}
        public void TestCustomMethod(int id, string hexBuffer)
        {
            CborOptions options = new CborOptions();

            options.Registry.ObjectMappingRegistry.Register <ObjectWithShouldSerialize2>(objectMapping =>
                                                                                         objectMapping
                                                                                         .AutoMap()
                                                                                         .ClearMemberMappings()
                                                                                         .MapMember(o => o.Id)
                                                                                         .SetShouldSerializeMethod(o => ((ObjectWithShouldSerialize2)o).Id != 12)
                                                                                         );

            ObjectWithShouldSerialize2 obj = new ObjectWithShouldSerialize2
            {
                Id = id
            };

            Helper.TestWrite(obj, hexBuffer, null, options);
        }
コード例 #2
0
        public void TestCustomMethod(int id, string json)
        {
            JsonSerializerOptions options = new JsonSerializerOptions();

            options.SetupExtensions();
            options.GetObjectMappingRegistry().Register <ObjectWithShouldSerialize2>(objectMapping =>
                                                                                     objectMapping
                                                                                     .AutoMap()
                                                                                     .ClearMemberMappings()
                                                                                     .MapMember(o => o.Id)
                                                                                     .SetShouldSerializeMethod(o => ((ObjectWithShouldSerialize2)o).Id != 12)
                                                                                     );

            ObjectWithShouldSerialize2 obj = new ObjectWithShouldSerialize2
            {
                Id = id
            };

            Helper.TestWrite(obj, json, options);
        }