Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to serialize a class that has both of two worlds

How to serialize a class that has both of two worlds

Scheduled Pinned Locked Moved C#
helpquestioncsharpwpfdesign
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sinosoidal
    wrote on last edited by
    #1

    hi, I want to serialize a class which has the two kinds of elements. Custom elements (non graphic and made by me, which are serializable by the XmlSerializer), and UI Elements from the WPF. The class which i want to serialize is this: Code Snippet public class Region : ISerializable { private Control _control; public Control Control { get { return _control; } set { _control = value; } } private Border _bounds; public Border Bounds { get { return _bounds; } set { _bounds = value; } } public Region() { } /// /// Initializes a new instance of the class. /// public Region(Border bounds) { _bounds = bounds; } public Region(SerializationInfo info, StreamingContext ctxt) { this._control = (Control)info.GetValue("Control", typeof(Control)); this._bounds = (Border)XamlReader.Load(new XmlTextReader(new StringReader((string)info.GetValue("Bounds", typeof(string))))); } public void GetObjectData(SerializationInfo info, StreamingContext ctxt) { info.AddValue("Control", this._control); info.AddValue("Bounds", XamlWriter.Save(_bounds)); } } As you can see, this class is composed by a Control (custom made class specified by me) and a Border (UI Element). The class was serializable if i didnt have the border on it. My attempt was to override the Iserialize methods in order to have serialization of the border based on XamlWriter.Save but it gives me error before getting there, in the following line: Code Snippet System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(typeof(Region)); With the message: Code Snippet "There was an error reflecting property 'Bounds'." How can i solve this problem? Thx, Nuno

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups