Esempio n. 1
0
 public AnsT3son(AnsT3 parent)
 {
     this.parent = parent;
     gendre      = "male";
     // expand parent
     parent.Expand(this);
 }
Esempio n. 2
0
        public void Test2Json_PC()
        {
            AnsT3 parent = new AnsT3();

            AnsT3Child c = new AnsT3Child(parent);
            // should trigger parent: io.odysz.anson.AnsT3
            AnsT3son son = new AnsT3son(parent);

            MemoryStream stream = new MemoryStream();

            parent.ToBlock(stream);
            string s      = Utils.ToString(stream);
            string expect = "{\"type\": \"io.odysz.anson.AnsT3\", \"ms\": null, "
                            + "\"m\": [{\"type\": \"io.odysz.anson.AnsT3Child\", \"ver\": \"0.9.xx\"}, "
                            + "{\"type\": \"io.odysz.anson.AnsT3son\", \"gendre\": \"male\", \"parent\": \"io.odysz.anson.AnsT3\", \"ver\": \"0.9.xx\"}], \"ver\": \"0.9.xx\"}";

            // in .net framwork 4.72, fields and properties are not always the same order
            Assert.AreEqual(expect.Length, s.Length);

            // should resolve parent ref with a type guess
            AnsT3 p = (AnsT3)Anson.FromJson(s);

            Assert.AreEqual(((AnsT3son)p.m[1]).gendre, "male");
            Assert.AreEqual(null, ((AnsT3Child)p.m[0]).parent);
            Assert.AreEqual(p, ((AnsT3son)p.m[1]).parent);

            AnsT3 p0 = (AnsT3)Anson.FromJson(expect);

            Assert.AreEqual(((AnsT3son)p0.m[1]).gendre, ((AnsT3son)p.m[1]).gendre);
            Assert.AreEqual(p0.ver, p.ver);
        }
Esempio n. 3
0
 public AnsT3Child(AnsT3 parent)
 {
     this.parent = parent;
     // expand parent
     parent.Expand(this);
 }