Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like this may be a Mono <code>XmlSerializer</code> limitation. I have a small test app which works under .NET, but not under Mono 3.0.6.</p> <p>But this looks fairly simple to work around:</p> <pre><code>[XmlIgnore] public Texture2D SideSprite { get; set; } [XmlElement("SideSprite")] [EditorBrowsable(EditorBrowsableState.Never)] public Texture2DProcessor SideSpriteProcessor { get { return SideSprite; } set { SideSprite = value; } } </code></pre> <p>We have the same issue in my Noda Time project, as XML serialization doesn't mix well with immutable types. I've given pretty much the <a href="http://noda-time.googlecode.com/hg/docs/userguide/serialization.html" rel="nofollow">same advice</a> there.</p> <p>EDIT: Okay, so here's some sample code which <em>does</em> work:</p> <pre><code>using System; using System.IO; using System.Xml; using System.Xml.Schema; using System.Xml.Serialization; public class Person { public string Name { get; set; } } public class PersonWrapper : IXmlSerializable { public Person Person { get; set; } public static implicit operator Person(PersonWrapper wrapper) { return wrapper == null ? null : wrapper.Person; } public static implicit operator PersonWrapper(Person person) { return new PersonWrapper { Person = person }; } public XmlSchema GetSchema() { return null; } public void ReadXml(XmlReader reader) { string name = reader.ReadString(); reader.ReadEndElement(); Person = new Person { Name = name }; } public void WriteXml(XmlWriter writer) { writer.WriteString(Person.Name); } } public class Company { [XmlElement(typeof(PersonWrapper))] public Person Director { get; set; } [XmlElement(typeof(PersonWrapper))] public Person Manager { get; set; } } class Test { static void Main() { var serializer = new XmlSerializer(typeof(Company)); var original = new Company { Director = new Person { Name = "Holly" }, Manager = new Person { Name = "Jon" } }; var writer = new StringWriter(); serializer.Serialize(writer, original); Console.WriteLine("XML:"); Console.WriteLine(writer.ToString()); var reader = new StringReader(writer.ToString()); var deserialized = (Company) serializer.Deserialize(reader); Console.WriteLine("Deserialized:"); Console.WriteLine("Director: {0}", deserialized.Director.Name); Console.WriteLine("Manager: {0}", deserialized.Manager.Name); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload