Can't seem to add XmlIgnore override on inherited property
11/22/2005 9:09:19 AM Can't seem to add XmlIgnore override on inherited property
By the way, I also posted this on DotNet Framework General.
I'm trying to serialize, via the XmlSerializer, an object which is derived
from System.Windows.Forms.Control. It throws an exception complaining about
not being able to serialize the Site property. I expected problems and my
plan was to work through them one at a time supplying an XmlIgnore attribute
for each of the properties it had problems with. However, for some reason
this doesn't seem to work. The code is below. Does anyone know why it's
still throwing the exception complaining about the Site property after
specifying the XmlIgnore attribute for that property?
using System;
using System.Windows.Forms;
using System.Xml.Serialization;
using System.IO;
using System.Drawing;
public class MyControl : Control
{
public MyControl()
{
}
}
public class Application
{
public static void Main()
{
MyControl control = new MyControl();
XmlSerializer serializer;
XmlAttributes attributes;
XmlAttributeOverrides overrides;
overrides = new XmlAttributeOverrides();
attributes = new XmlAttributes();
attributes.XmlIgnore = true;
overrides.Add(typeof(MyControl), "Site", attributes);
control.Font = new Font("Arial", 12);
serializer = new XmlSerializer(typeof(MyControl), overrides);
serializer.Serialize(Console.OpenStandardOutput(), control);
}
}
--
Thanks,
Nick
11/30/2005 9:47:38 PM Re: Can't seem to add XmlIgnore override on inherited property
I don't know if you'll ever succeed doing what you want, serializing the
state of a control, but anyway I can answer your question on the xml
attribute overrides.
you want:
overrides.Add(typeof(System.ComponentModel.Component), "Site", attributes);
The overrides.Add() wants a name of a type, and also a member name within that type, to override.
Your type MyControl has no member by the name Site.
The Site member is on the type System.ComponentModel.Component, which is the base type of Control.
-Dino
--
-Dino
浙公网安备 33010602011771号