Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C# Serialization
Message
 
À
27/06/2011 16:50:07
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Divers
Thread ID:
01516342
Message ID:
01516390
Vues:
52
I was thinking that you could add a DataToXML extension or somthing similar, that way the amount of data passed over the wire would be smaller than sending the whole class.


>>Is there any real benefit to serializing a class versus just the data the class contains?
>
>I don't know, but it certainly is easier serializing the whole class (I assume anyway ... since I haven't done it the other way, of serializing just the data).
>
>
>[Serializable]
>public class MyClass
>{
>    // put properties and methods here
>
>    // static method to serialize the class
>    public static string GetString(MyClass message)
>    {
>        XmlSerializer x = new XmlSerializer(typeof(MyClass));
>        using (StringWriter sw = new StringWriter())
>        {
>            x.Serialize(sw, message);
>            return sw.ToString();
>        }
>    }
>
>    // static method to de-serialize the class
>    public static MyClass GetObject(string xml)
>    {
>	MyClass message = null;
>
>	try
>	{
>		StringReader sr = new StringReader(xml);
>		XmlSerializer x = new XmlSerializer(typeof(MyClass));
>		message = (MyClass)x.Deserialize(sr);
>	}
>	catch
>	{
>	}
>
>	return message;
>    }
>}
>
>
>Pretty easy, huh?
>
>~~Bonnie
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform