public static TestClass FromDoc(TestClass existing, DocNode doc) { if (doc.Type != DocNodeType.List) { throw new System.ArgumentException("Not a list! " + doc.Type); } if (doc[0].StringValue == "Derived") { TestClassDerived derivedExisting; if (existing is TestClassDerived) { derivedExisting = (TestClassDerived)existing; } else { derivedExisting = new TestClassDerived(); } derivedExisting.derivedKey = Convert.ToInt32(doc[1].StringValue, System.Globalization.CultureInfo.InvariantCulture); return(derivedExisting); } else { if (!(existing is TestClass)) { existing = new TestClass(); } existing.baseKey = Convert.ToInt32(doc[1].StringValue, System.Globalization.CultureInfo.InvariantCulture); return(existing); } }
public void FromDoc_UpdatesDerived() { TestClass tc = new TestClassDerived { baseKey = 1, derivedKey = 2 }; var saved = tc; var doc = Config.LoadDocFromString("[\"Derived\", 66]", c_filename); ConfigReifier.Reify(ref tc, doc); Assert.AreSame(tc, saved); Assert.AreEqual(tc.baseKey, 1); Assert.AreEqual(((TestClassDerived)tc).derivedKey, 66); }
public void FromDoc_UpdatesDerived_AsBase() { TestClass tc = new TestClassDerived { baseKey = 4, derivedKey = 5 }; var saved = tc; var doc = Config.LoadDocFromString("[\"Base\", 123]", c_filename); ConfigReifier.Reify(ref tc, doc); Assert.AreSame(tc, saved); Assert.AreEqual(tc.baseKey, 123); Assert.AreEqual(((TestClassDerived)tc).derivedKey, 5); }
public void FromDoc_UpdatesDerived() { TestClass tc = new TestClassDerived { baseKey = 1, derivedKey = 2 }; var saved = tc; var doc = Configs.ParseString("[\"Derived\", 66]", FILENAME); Configs.Reify(ref tc, doc); Assert.AreSame(tc, saved); Assert.AreEqual(tc.baseKey, 1); Assert.AreEqual(((TestClassDerived)tc).derivedKey, 66); }
public void FromDoc_UpdatesDerived_AsBase() { TestClass tc = new TestClassDerived { baseKey = 4, derivedKey = 5 }; var saved = tc; var doc = Configs.ParseString("[\"Base\", 123]", FILENAME); Configs.Reify(ref tc, doc); Assert.AreSame(tc, saved); Assert.AreEqual(tc.baseKey, 123); Assert.AreEqual(((TestClassDerived)tc).derivedKey, 5); }