Wednesday, July 01, 2009

Generic Serialization Method - Microsoft C#.NET

using System.Xml.Serialization;
using System.Text;
public class SerializeManager
{
    public static XmlDocument Serialize(Type type, Object source)
    {
        MemoryStream stream = null;
        TextWriter writer = null;
        XmlDocument document = null;
        try
        {
            stream = new MemoryStream();
            writer = new StreamWriter(stream, Encoding.Unicode);
            XmlSerializer serializer = new XmlSerializer(type);
            serializer.Serialize(writer, source);
            int count = (int)stream.Length;
            byte[] array = new byte[count];
            stream.Seek(0, SeekOrigin.Begin);
            stream.Read(array, 0, count);
            UnicodeEncoding utf = new UnicodeEncoding();
            document = new XmlDocument();
            document.LoadXml(utf.GetString(array).Trim());
        }
        catch 
        {
            throw;
        }
        finally
        {
            if (stream != null) stream.Close();
            if (writer != null) writer.Close();
        }
        return document;
    }
}

Generic Clone Method C#.NET

Using reflection, this method copies each property of the source object to target object.

public virtual void Clone(Object source)
{
    if (source == null)
        throw new ArgumentNullException("Source");
    if (source.GetType() != this.GetType())
        throw new ArgumentException("Type Mismatch");
    foreach (PropertyInfo p in source.GetType().GetProperties())
        if (p.CanRead && p.CanWrite)
            p.SetValue(this, p.GetValue(source, null), null);
}

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...