示例#1
0
        private static object Import(bool hasValue, string input)
        {
            JsonReader    reader        = JsonText.CreateReader(input);
            ImportContext context       = JsonConvert.CreateImportContext();
            ThingImporter thingImporter = new ThingImporter();

            context.Register(thingImporter);
            NullableImporter importer = new NullableImporter(typeof(Thing?));
            object           thing    = importer.Import(context, reader);

            Assert.AreEqual(hasValue, thingImporter.ImportCalled);
            if (hasValue)
            {
                Assert.IsInstanceOfType(typeof(Thing), thing);
            }
            else
            {
                Assert.IsNull(thing);
            }
            Assert.IsTrue(reader.EOF, "Reader must be at EOF.");
            return(thing);
        }
示例#2
0
 private static object Import(bool hasValue, string input)
 {
     JsonReader reader = JsonText.CreateReader(input);
     ImportContext context = JsonConvert.CreateImportContext();
     ThingImporter thingImporter = new ThingImporter();
     context.Register(thingImporter);
     NullableImporter importer = new NullableImporter(typeof(Thing?));
     object thing = importer.Import(context, reader);
     Assert.AreEqual(hasValue, thingImporter.ImportCalled);
     if (hasValue)
         Assert.IsInstanceOfType(typeof(Thing), thing);
     else
         Assert.IsNull(thing);
     Assert.IsTrue(reader.EOF, "Reader must be at EOF.");
     return thing;
 }