コード例 #1
0
        public void Interface()
        {
            CborOptions options = new CborOptions();

            options.Registry.ObjectMappingRegistry.Register <IFoo>(objectMapping =>
                                                                   objectMapping
                                                                   .AutoMap()
                                                                   .MapCreator(o => new Foo())
                                                                   );

            const string        hexBuffer = "A163466F6FA16249640C";
            ObjectWithInterface obj       = Helper.Read <ObjectWithInterface>(hexBuffer, options);

            Assert.NotNull(obj);
            Assert.NotNull(obj.Foo);
            Assert.IsType <Foo>(obj.Foo);
            Assert.Equal(12, obj.Foo.Id);

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

            options.SetupExtensions();
            options.GetObjectMappingRegistry().Register <IFoo>(objectMapping =>
                                                               objectMapping
                                                               .AutoMap()
                                                               .MapCreator(o => new Foo())
                                                               );

            const string        json = @"{""Foo"":{""Id"":12}}";
            ObjectWithInterface obj  = Helper.Read <ObjectWithInterface>(json, options);

            Assert.NotNull(obj);
            Assert.NotNull(obj.Foo);
            Assert.IsType <Foo>(obj.Foo);
            Assert.Equal(12, obj.Foo.Id);

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