Porting WinForms-Developed desktop applications to the Silverlight-developed RIA (part 1th)

Source: Internet
Author: User
Tags foreach serialization silverlight

1,serializableattribute does not exist

In Silverlight, SerializableAttribute is no longer included, but without this tag does not affect serialization. The reason for removing this attribute tag is because a series of attribute tokens that have been used to serialize the XML have been started.

For this change, there is no difficulty, the main is more trouble, need to delete. Of course, if you do not want to delete, the easiest way is to create a serializableattribute yourself.

2,dictionary XML serialization, using XElement instead of XmlDocument, convert.changetype parameter changes

Speaking, it is not in Silverlight, there is no way to use XmlSerializer to serialize dictionary<>. And I directly implemented a Dictionary that can be serialized in XML, the code is as follows:

public class Xmlserdictionary<tkey, tvalue>: Dictionary<tkey, Tvalue>, IXmlSerializable
{
#region IXmlSerializable Members

System.Xml.Schema.XmlSchema Ixmlserializable.getschema ()
{
return null;
}

void Ixmlserializable.readxml (System.Xml.XmlReader reader)
{
XmlDocument doc = new XmlDocument ();
Doc. Loadxml (reader. ReadOuterXml ());

foreach (XmlElement item in Doc. childnodes [0]. ChildNodes)
{
TKey key = (TKey) convert.changetype (item. GetAttribute ("key"), typeof (TKey));
Tvalue value = (Tvalue) convert.changetype (item. InnerText, typeof (Tvalue));
This. ADD (key, value);
}
}

void Ixmlserializable.writexml (System.Xml.XmlWriter writer)
{
foreach (var item in this)
{
Writer. WriteStartElement ("item");
Writer. WriteAttributeString ("Key", item. Key.tostring ());
Writer. WriteValue (item. Value);
Writer. WriteEndElement ();
}
}

#endregion
}

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.