Show / Hide Table of Contents

    Class StreamExtensions

    Stream 扩展方法

    Inheritance
    Object
    StreamExtensions
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    Object.ToString()
    Namespace: Lett.Extensions
    Assembly: Lett.Extensions.dll
    Syntax
    public static class StreamExtensions

    Methods

    | Improve this Doc View Source

    Deserialize<T>(Stream)

    反序列化

    formatter: BinaryFormatter

    类型转换失败,返回 default(T)

    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

    类型

    | Improve this Doc View Source

    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

    this is null

    ArgumentNullException

    filePath is null

    NotSupportedException

    filePath is not supported

    | Improve this Doc View Source

    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

    this is null

    ArgumentNullException

    filePath is null

    ArgumentOutOfRangeException

    bufferSizemust greater than zero

    NotSupportedException

    filePath is not supported

    • Improve this Doc
    • View Source
    Back to top Copyright (c) 2019 viacooky. All rights reserved.