添加项目文件。
This commit is contained in:
27
common/Tnb.Common/Extension/StreamExtensions.cs
Normal file
27
common/Tnb.Common/Extension/StreamExtensions.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using JNPF.DependencyInjection;
|
||||
using System.Text;
|
||||
|
||||
namespace JNPF.Common.Extension;
|
||||
|
||||
/// <summary>
|
||||
/// Stream扩展方法.
|
||||
/// </summary>
|
||||
[SuppressSniffer]
|
||||
public static class StreamExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 把<see cref="Stream"/>转换为<see cref="string"/>.
|
||||
/// </summary>
|
||||
public static string ToString2(this Stream stream, Encoding? encoding = null)
|
||||
{
|
||||
if (encoding == null)
|
||||
{
|
||||
encoding = Encoding.UTF8;
|
||||
}
|
||||
|
||||
using (StreamReader reader = new StreamReader(stream, encoding))
|
||||
{
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user