C# DataSet to Object Array Extension Method

3. February 2010
ObjectArray[] objectArray = DataSet.ToSpecifiedObject<ObjectArray[]>();

public static T ToSpecifiedObject<T>(this DataSet value)
{
    byte[] buf = System.Text.UTF8Encoding.UTF8.GetBytes(value.GetXml());
    MemoryStream ms = new MemoryStream(buf);
    XmlSerializer ser = new XmlSerializer(typeof(T));
    object obj = ser.Deserialize(ms);

    return (T)obj;
}




Bookmark it!

.NET, C#, Extension Method , , , ,


Comments are closed