Class StreamExtensions
Stream 扩展方法
Inherited Members
Namespace: Lett.Extensions
Assembly: Lett.Extensions.dll
Syntax
public static class StreamExtensions
Methods
| Improve this Doc View SourceDeserialize<T>(Stream)
Declaration
public static T Deserialize<T>(this Stream this)
Parameters
Type | Name | Description |
---|---|---|
Stream | this |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
Examples
var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
var rs = fs.Deserialize<MyClass>();
|
Improve this Doc
View Source
Deserialize<T>(Stream, IFormatter)
反序列化
类型转换失败,返回 default(T)
Declaration
public static T Deserialize<T>(this Stream this, IFormatter formatter)
Parameters
Type | Name | Description |
---|---|---|
Stream | this | |
IFormatter | formatter | 格式化器 |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T | 类型 |
SaveAsFile(Stream, String)
保存为文件
FileMode.Create | bufferSize: 81920
Declaration
public static void SaveAsFile(this Stream this, string filePath)
Parameters
Type | Name | Description |
---|---|---|
Stream | this | |
String | filePath |
Examples
var ms = new MemoryStream(myBytes);
ms.SaveToFile(filePath);
|
Improve this Doc
View Source
SaveAsFile(Stream, String, FileMode)
保存为文件
bufferSize: 81920
Declaration
public static void SaveAsFile(this Stream this, string filePath, FileMode fileMode)
Parameters
Type | Name | Description |
---|---|---|
Stream | this | |
String | filePath | 文件路径 |
FileMode | fileMode | 文件打开方式 |
Examples
var ms = new MemoryStream(myBytes);
ms.SaveToFile(filePath, FileMode.Append);
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentNullException |
|
NotSupportedException |
|
SaveAsFile(Stream, String, FileMode, Int32)
保存为文件
Declaration
public static void SaveAsFile(this Stream this, string filePath, FileMode fileMode, int bufferSize)
Parameters
Type | Name | Description |
---|---|---|
Stream | this | |
String | filePath | 文件路径 |
FileMode | fileMode | 文件打开方式 |
Int32 | bufferSize | 缓冲区大小 |
Examples
var ms = new MemoryStream(myBytes);
ms.SaveToFile(filePath, FileMode.Append, 1024);
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
NotSupportedException |
|