Exemplo n.º 1
0
        public void Write_ReadOnlyPropertyContainer()
        {
            var obj = new ReadOnlyPropertyContainer()
            {
                Foo = "x"
            };

            Assert.AreEqual(ReadXml("ReadOnlyPropertyContainer.xml").Trim(), XamlServices.Save(obj), "#1");

            var sw = new StringWriter();
            var xw = new XamlXmlWriter(sw, new XamlSchemaContext());
            var xt = xw.SchemaContext.GetXamlType(obj.GetType());

            xw.WriteStartObject(xt);
            xw.WriteStartMember(xt.GetMember("Bar"));
            xw.WriteValue("x");
            xw.WriteEndMember();
            xw.WriteEndObject();
            xw.Close();
            Assert.IsTrue(sw.ToString().IndexOf("Bar") > 0, "#2");                // it is not rejected by XamlXmlWriter. But XamlServices does not write it.
        }
Exemplo n.º 2
0
        public void Read_ReadOnlyPropertyContainer()
        {
            var obj = new ReadOnlyPropertyContainer()
            {
                Foo = "x"
            };
            var xr = new XamlObjectReader(obj);
            var xt = xr.SchemaContext.GetXamlType(obj.GetType());

            while (xr.Read())
            {
                if (xr.NodeType == XamlNodeType.StartMember)
                {
                    break;
                }
            }
            Assert.AreEqual(xt.GetMember("Foo"), xr.Member, "#1");
            while (!xr.IsEof)
            {
                xr.Read();
            }
        }