Serialization in C# without using file system
2010-02-10 11:33
267 查看
原文:http://stackoverflow.com/questions/302821/serialization-in-c-without-using-file-system
public static byte[] Serialize<T>(T t) {
IFormatter formatter = new BinaryFormatter();
using (MemoryStream stream = new MemoryStream()) {
formatter.Serialize(stream, t);
return stream.ToArray();
}
}
public static T Deserialize<T>(byte[] b) {
IFormatter formatter = new BinaryFormatter();
using (MemoryStream stream = new MemoryStream(b)) {
return (T)formatter.Deserialize(stream);
}
}
public static byte[] Serialize<T>(T t) {
IFormatter formatter = new BinaryFormatter();
using (MemoryStream stream = new MemoryStream()) {
formatter.Serialize(stream, t);
return stream.ToArray();
}
}
public static T Deserialize<T>(byte[] b) {
IFormatter formatter = new BinaryFormatter();
using (MemoryStream stream = new MemoryStream(b)) {
return (T)formatter.Deserialize(stream);
}
}
相关文章推荐
- Creating a XML Document from scratch without using a file in C#
- C#.NET: Compress/Decompress zip file using System.IO.Packaging
- Uploading File using Ajax and receiving binary data in Asp.net (C#)[转]
- ?? [SQL Server] -- Using FILESTREAM to Store BLOBs in the NTFS File System in SQL Server 2008
- Using ZipLib to create a Zip File in C#
- c#中using System.Runtime.Serialization.Json;不能引用
- Local File Manage in JavaScript Using FileSystemObject
- How to Take Ownership of a File/Folder Using Command-Line in Windows 7 or newer version System
- File Uploading in ASP.NET Using C#
- Local File Manage in JavaScript Using FileSystemObject
- BI Java 补丁错误处理 :Cannot login to the SAP J2EE Engine using user and password as provided in the Filesystem Secure Store. Enter va
- You cannot access the client's file system using the FileSystemObject in your ASP code
- How To Install 11.2 / 12.1 Database/Client Software In Silent Mode Without Using Response File
- can I read/write the routing table in C without using system() command?
- How to upload a file via a HTTP multipart request in Java without using any external libraries
- Obtaining (and managing) file and folder icons using SHGetFileInfo in C#
- You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.
- Get and display the size of file and directory in Linux system using du command 获取和现实linux文件大小(三)
- [存底]使用C#压缩/解压缩7-zip文件 zip/Unzip file using 7-zip in C#
- SQLite Practice Using C# in Windows