public static void SerializeToLocalStorage(this object value, string fullPath)
{
if (value == null)
throw (new ArgumentNullException("Value cannot be NULL.", "value"));
string file = null;
string[] paths = fullPath.Split('\\');
if (paths.Length < 1 || string.IsNullOrWhiteSpace(paths[0]))
throw (new ArgumentException("This is not a valid path for LocalStorage.", "filename"));
file = paths[paths.Length - 1];
MemoryStream stream = new MemoryStream();
DataContractSerializer serializer = new DataContractSerializer(value.GetType());
serializer.WriteObject(stream, value);
stream.Seek(0, SeekOrigin.Begin);
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, (int)stream.Length);
File.WriteAllBytes(fullPath, buffer);
stream.Flush();
stream.Close();
}