I have a class containing the Brush MyBrush property, marked as [XmlIgnore] . However, it serializes in the stream, causing problems reading from XamlReader .
I did some tests, for example. when the visibility of the property (for internal) changes, it disappears in the stream. Unfortunately, I cannot do this in my specific scenario.
- Has anyone had the same problem and?
- Do you see any way around this?
Note: C # 4.0, as far as I can tell
This is the method from my Unit Test, where I am testing XamlSerialization :
// buffer to a StringBuilder StringBuilder sb = new StringBuilder(); XmlWriter writer = XmlWriter.Create(sb, settings); XamlDesignerSerializationManager manager = new XamlDesignerSerializationManager(writer) {XamlWriterMode = XamlWriterMode.Expression}; XamlWriter.Save(testObject, manager); xml = sb.ToString(); Assert.IsTrue(!String.IsNullOrEmpty(xml) && !String.IsNullOrEmpty(xml), "Xaml Serialization failed for " + testObject.GetType() + " no xml string available"); xml = sb.ToString(); MemoryStream ms = xml.StringToStream(); object root = XamlReader.Load(ms); Assert.IsTrue(root != null, "After reading from MemoryStream no result for Xaml Serialization");
In one of my classes, I use the Brush Property. In the above code, tests of this module are not performed because the value is Brush (not serializable). When I remove Setter (as shown below), Unit Test passes.
Using XmlWriter (basically the same test as above), it works. In StringBuffer sb I see that Property Brush serialized when the setter exists, and not when it is deleted (most likely, another check ignores the property due to the lack of a setter). Other properties using [XmlIgnore] ignored as intended.
[XmlIgnore] public Brush MyBrush { get { ..... }
Horst walter
source share