MovGP0 | Über mich | Hilfen | Artikel | Weblinks | Literatur | Zitate | Notizen | Programmierung | MSCert | Physik |
|
Serialization
BearbeitenAttribute
BearbeitenXML Serializer Attribut[1] | Newtonsoft.Json Attribute[2] |
---|---|
|
|
Immutable Serialization
BearbeitenXmlSerializer
kann immutable Datentypen nicht deserialisieren. Benötigt Implementierung vonIXmlSerializable
.DataContractSerializer
undBinaryFormatter
kann immutable serialisieren.
[ImmutableObject(true)]
public class Address: IXmlSerializable
{
private Address()
{
}
public Address(string city, string street, int house)
{
this.City = city;
this.Street = street;
this.HouseNumber = house;
}
public string City { get; private set; }
public string Street { get; private set; }
public int HouseNumber { get; private set; }
#region IXmlSerializable Members
public XmlSchema GetSchema()
{
return null;
}
public void ReadXml(XmlReader reader)
{
this.City = reader.ReadElementString();
this.Street = reader.ReadElementString();
this.HouseNumber = int.Parse(reader.ReadElementString());
}
public void WriteXml(XmlWriter writer)
{
writer.WriteElementString("City", this.City);
writer.WriteElementString("Street", this.Street);
writer.WriteElementString("HouseNumber", this.HouseNumber.ToString());
}
#endregion
}
Referenzen
Bearbeiten- ↑ Attributes That Control XML Serialization. In: MSDN. Microsoft, abgerufen am 30. Mai 2014 (englisch).
- ↑ Serialization Attributes. In: Json.NET Documentation. Newton King, abgerufen am 30. Mai 2014.
|}