Hi,
The release 1.2 of Sb2.Extensions is available on CodePlex now.
Here is the Checkin change notes :
Create Release 1.2 Branch
[assembly: AssemblyVersion("1.2")]
Changes :
Added Generic Binary Serialize and Deserialize Extension Methods
Added DbHelper Extensions for DataReader Deserialization
Added the Split<> Extension Method
Added Generic Object Shallow Copy Extension
Generic Binary Serialize and Deserialize
Serialize
public static byte[] Serialize<T>(this T o) where T : class
{
Type type = o.GetType();
if ((type.Attributes & TypeAttributes.Serializable) == 0)
throw new Exception("The Specified object must have [Serializable] attribute");
var formatter = new BinaryFormatter();
using (MemoryStream ms = new MemoryStream())
{
formatter.Serialize(ms, o);
return ms.ToArray();
}
}
[Serializable]
public class Test
{
public String Name { get; set; }
}
byte[] data = obj1.Serialize<Test>();
Console.WriteLine(data.Length);
Deserialize
public static T Deserialize<T>(this byte[] data) where T : class
{
var formatter = new BinaryFormatter();
using (MemoryStream ms = new MemoryStream(data))
{
return formatter.Deserialize(ms) as T;
}
}
[Serializable]
public class Test
{
public String Name { get; set; }
}
Test t = data.Deserialize<Test>();
Console.WriteLine(t.Name);
DbHelper Extensions for DataReader Deserialization
More infos here : http://blog.sb2.fr/post/2008/11/14/DbHelper-Extensions.aspx
Split<> Extension
More infos here : http://blog.sb2.fr/post/2008/11/28/Splitting-an-IList-to-n-IList-Method-extension.aspx
Generic Object Shallow Copy Extension
More infos here : http://blog.sb2.fr/post/2008/11/30/Creates-a-shallow-copy-of-any-Objects-with-Generic-Extension-Method.aspx
Stay Tuned :)
Views(1074)

