|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to prevent base class form being serializedserialization and deserialization with this calss but I get an exception "Cannot serialize member System.ComponentModel.Component.Site of type System.ComponentModel.ISite because it is an interface.". I am not interested in serializing any member from the base class only the properties in the derived class. How can I prevent the entire base class from being serialized? Code snippet public partial class UserControl1 : UserControl { private int item1; private string item2; public UserControl1() { } public int Item1 { get {return item1;} set {item1 = value;} } public string Item2 { get { return item2; } set { item2 = value; } } } public partial class Form1 : Form { private UserControl1 Uctrl1; . . . Uctrl1 = new UserControl1(); Uctrl1.Item1 = 3; Uctrl1.Item2 = "This is a test"; . . . XmlSerializer mySerializer = new XmlSerializer(typeof(UserControl1)); // To write to a file, create a StreamWriter object. StreamWriter myWriter = new StreamWriter("myFileName.xml"); mySerializer.Serialize(myWriter, Uctrl1); myWriter.Close(); } |
|||||||||||||||||||||||