Generic List<T> to DataTable using Reflection

The following function takes in a System.Collections.Generic.List<T> and returns a System.Data.DataTable with the properties (via reflection) of T as columns.

public static System.Data.DataTable ListToDataTable<T>(
    System.Collections.Generic.IList<T> elements)
{
    System.Reflection.PropertyInfo[] arrPropInfo = typeof(T).GetProperties();
    System.Data.DataTable dt = new DataTable();
    System.Data.DataRow dr;

    foreach (System.Reflection.PropertyInfo pInfo in arrPropInfo)
    {
        dt.Columns.Add(pInfo.Name, pInfo.PropertyType);
    }
    foreach(object elem in elements)
    {
        dr = dt.NewRow();
        foreach (System.Reflection.PropertyInfo pInfo in arrPropInfo)
        {
            dr[pInfo.Name] = pInfo.GetValue(elem, null);
        }
        dt.Rows.Add(dr);
    }

    return dt;
}

C# Serialization

Xml Serialization and Binary Serialization to a Base64 string

Xml Serialization

Snippit: Take a serializable object and serialize it into an xml string, stored in a System.Text.StringBuilder

System.Xml.Serialization.XmlSerializer serializer = 
    new System.Xml.Serialization.XmlSerializer(typeof(ObjectToSerialize));
System.Text.StringBuilder sb = new System.Text.StringBuilder();
using (System.IO.StringWriter stringWriter = new System.IO.StringWriter(sb))
{
    serializer.Serialize(stringWriter,  myObject);
    stringWriter.Close();
}

Binary Serialization to Base64 string

Snippit: Take a serializable object and serialize it into a Base64 string

byte[] bResult;
System.Runtime.Serialization.IFormatter formatter =
    new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
using (System.IO.MemoryStream s = new System.IO.MemoryStream())
{
    formatter.Serialize(s, myObject);
    bResult = s.ToArray();
    s.Close();
}
string s = Convert.ToBase64String(bResult);

Snippit: Deserialize

ObjectToSerialize myObject = null;
byte[] b = Convert.FromBase64String(str);
System.Runtime.Serialization.IFormatter formatter =
    new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
using (System.IO.MemoryStream ms = System.IO.new MemoryStream(b))
{
    myObject = (ObjectToSerialize)formatter.Deserialize(ms);
    ms.Close();
}