0% found this document useful (0 votes)
31 views1 page

Serialization Cs

Uploaded by

devi das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views1 page

Serialization Cs

Uploaded by

devi das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

26/11/2024 10:26 Serialization.

cs

using System;
using [Link];
using [Link];
using [Link];
using [Link];

namespace [Link]
{
public class Serialization<T> where T : class
{
/// <summary>
/// Serailize object to string
/// </summary>
/// <param name="o">Object to be serialized</param>
/// <returns></returns>
public static string SerializeObject(T o)
{
DataContractSerializer dcs = new DataContractSerializer([Link]());

using (MemoryStream ms = new MemoryStream())


{
using (XmlDictionaryWriter xdw = [Link](ms))
{
[Link](xdw, o);
[Link]();
[Link] = 0;
XmlDocument xmlDoc = new XmlDocument();
[Link](ms);
return [Link];
}
}
}

/// <summary>
/// Deserialize string to object
/// </summary>
/// <param name="sXmlDoc">XML representation of the object </param>
/// <returns></returns>
public static T DeserializeObject(string sXmlDoc)
{
if ([Link](sXmlDoc))
return [Link](typeof(T)) as T; // return empty object

return Deserialize(sXmlDoc);
}

/// <summary>
/// Deserialize string to object
/// </summary>
/// <param name="sXmlDoc">XML representation of the object </param>
/// <returns></returns>
private static T Deserialize(string sXmlDoc)
{
DataContractSerializer dcs = new DataContractSerializer(typeof(T));
using (MemoryStream ms = new MemoryStream([Link](sXmlDoc)))
{
object result = [Link](ms);
return result as T;
}
}
}
}

[Link] cloud/drive-download-20241126T092541Z-001/[Link] 1/1

You might also like