日韩成人免费在线_国产成人一二_精品国产免费人成电影在线观..._日本一区二区三区久久久久久久久不

當前位置:首頁 > 科技  > 軟件

C#開源實用的工具類庫,集成超過1000多種擴展方法

來源: 責編: 時間:2024-05-30 09:11:21 187觀看
導讀前言今天大姚給大家分享一個C#開源(MIT License)、免費、實用且強大的工具類庫,集成超過1000多種擴展方法增強 .NET Framework 和 .NET Core的使用效率:Z.ExtensionMethods。直接項目引入類庫使用在你的對應項目中NuGet包

前言

今天大姚給大家分享一個C#開源(MIT License)、免費、實用且強大的工具類庫,集成超過1000多種擴展方法增強 .NET Framework 和 .NET Core的使用效率:Z.ExtensionMethods。MN128資訊網——每日最新資訊28at.com

直接項目引入類庫使用

在你的對應項目中NuGet包管理器中搜索:Z.ExtensionMethods安裝即可使用。MN128資訊網——每日最新資訊28at.com

支持.NET Standard 2.0和.NET Framework 4.0 。MN128資訊網——每日最新資訊28at.com

圖片圖片MN128資訊網——每日最新資訊28at.com

項目源代碼

圖片圖片MN128資訊網——每日最新資訊28at.com

部分擴展方法展示

MD5哈希算法

public static partial class Extensions{    /// <summary>    /// A Stream extension method that converts the @this to a md 5 hash.    /// </summary>    /// <param name="this">The @this to act on.</param>    /// <returns>@this as a string.</returns>    public static string ToMD5Hash(this Stream @this)    {        using (MD5 md5 = MD5.Create())        {            byte[] hashBytes = md5.ComputeHash(@this);            var sb = new StringBuilder();            foreach (byte bytes in hashBytes)            {                sb.Append(bytes.ToString("X2"));            }            return sb.ToString();        }    }}

解壓GZip字節數組

public static partial class Extensions{    /// <summary>    /// A byte[] extension method that decompress the byte array gzip to string.    /// </summary>    /// <param name="this">The @this to act on.</param>    /// <returns>The byte array gzip to string.</returns>    public static string DecompressGZip(this byte[] @this)    {        const int bufferSize = 1024;        using (var memoryStream = new MemoryStream(@this))        {            using (var zipStream = new GZipStream(memoryStream, CompressionMode.Decompress))            {                // Memory stream for storing the decompressed bytes                using (var outStream = new MemoryStream())                {                    var buffer = new byte[bufferSize];                    int totalBytes = 0;                    int readBytes;                    while ((readBytes = zipStream.Read(buffer, 0, bufferSize)) > 0)                    {                        outStream.Write(buffer, 0, readBytes);                        totalBytes += readBytes;                    }                    return Encoding.Default.GetString(outStream.GetBuffer(), 0, totalBytes);                }            }        }    }    /// <summary>    /// A byte[] extension method that decompress the byte array gzip to string.    /// </summary>    /// <param name="this">The @this to act on.</param>    /// <param name="encoding">The encoding.</param>    /// <returns>The byte array gzip to string.</returns>    public static string DecompressGZip(this byte[] @this, Encoding encoding)    {        const int bufferSize = 1024;        using (var memoryStream = new MemoryStream(@this))        {            using (var zipStream = new GZipStream(memoryStream, CompressionMode.Decompress))            {                // Memory stream for storing the decompressed bytes                using (var outStream = new MemoryStream())                {                    var buffer = new byte[bufferSize];                    int totalBytes = 0;                    int readBytes;                    while ((readBytes = zipStream.Read(buffer, 0, bufferSize)) > 0)                    {                        outStream.Write(buffer, 0, readBytes);                        totalBytes += readBytes;                    }                    return encoding.GetString(outStream.GetBuffer(), 0, totalBytes);                }            }        }    }}

將泛型數組轉換為DataTable

public static partial class Extensions{    /// <summary>    /// A T[] extension method that converts the @this to a data table.    /// </summary>    /// <typeparam name="T">Generic type parameter.</typeparam>    /// <param name="this">The @this to act on.</param>    /// <returns>@this as a DataTable.</returns>    public static DataTable ToDataTable<T>(this T[] @this)    {        Type type = typeof (T);        PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);        FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance);        var dt = new DataTable();        foreach (PropertyInfo property in properties)        {            dt.Columns.Add(property.Name, property.PropertyType);        }        foreach (FieldInfo field in fields)        {            dt.Columns.Add(field.Name, field.FieldType);        }        foreach (T item in @this)        {            DataRow dr = dt.NewRow();            foreach (PropertyInfo property in properties)            {                dr[property.Name] = property.GetValue(item, null);            }            foreach (FieldInfo field in fields)            {                dr[field.Name] = field.GetValue(item);            }            dt.Rows.Add(dr);        }        return dt;    }}

支持在線搜索和演示

在線地址:https://csharp-extension.com/en/online-example/MN128資訊網——每日最新資訊28at.com

圖片圖片MN128資訊網——每日最新資訊28at.com

搜索ToMD5Hash:MN128資訊網——每日最新資訊28at.com

圖片圖片MN128資訊網——每日最新資訊28at.com

使用.NET Fiddle在線演示:MN128資訊網——每日最新資訊28at.com

圖片 圖片 MN128資訊網——每日最新資訊28at.com

本文鏈接:http://www.www897cc.com/showinfo-26-91685-0.htmlC#開源實用的工具類庫,集成超過1000多種擴展方法

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。郵件:2376512515@qq.com

上一篇: 面試官:說說Netty核心組件?

下一篇: 尤雨溪:這個前端經典輪子值得去造!

標簽:
  • 熱門焦點
  • 對標蘋果的靈動島 華為帶來實況窗功能

    繼蘋果的靈動島之后,華為也在今天正式推出了“實況窗”功能。據今天鴻蒙OS 4.0的現場演示顯示,華為的實況窗可以更高效的展現出實時通知,比如鎖屏上就能看到外賣、打車、銀行
  • vivo TWS Air開箱體驗:真輕 臻好聽

    在vivo S15系列新機的發布會上,vivo的最新款真無線藍牙耳機vivo TWS Air也一同發布,本次就這款耳機新品給大家帶來一個簡單的分享。外包裝盒上,vivo TWS Air保持了vivo自家產
  • 容量越大越不壞?24萬塊硬盤故障率報告公布 這些產品零故障

    8月5日消息,云存儲服務商Backblaze發布了最新的硬盤故障率報告,年故障率有所上升。Backblaze發布的硬盤季度統計數據,其中包括故障率等重要方面。這些結
  • Rust中的高吞吐量流處理

    作者 | Noz編譯 | 王瑞平本篇文章主要介紹了Rust中流處理的概念、方法和優化。作者不僅介紹了流處理的基本概念以及Rust中常用的流處理庫,還使用這些庫實現了一個流處理程序
  • 一文看懂為蘋果Vision Pro開發應用程序

    譯者 | 布加迪審校 | 重樓蘋果的Vision Pro是一款混合現實(MR)頭戴設備。Vision Pro結合了虛擬現實(VR)和增強現實(AR)的沉浸感。其高分辨率顯示屏、先進的傳感器和強大的處理能力
  • 不容錯過的MSBuild技巧,必備用法詳解和實踐指南

    一、MSBuild簡介MSBuild是一種基于XML的構建引擎,用于在.NET Framework和.NET Core應用程序中自動化構建過程。它是Visual Studio的構建引擎,可在命令行或其他構建工具中使用
  • 得物效率前端微應用推進過程與思考

    一、背景效率工程隨著業務的發展,組織規模的擴大,越來越多的企業開始意識到協作效率對于企業團隊的重要性,甚至是決定其在某個行業競爭中突圍的關鍵,是企業長久生存的根本。得物
  • 華為和江淮汽車合作開發百萬元問界MPV?雙方回應來了

    8月1日消息,郭明錤今天在社交平臺發文稱,華為正在和江淮汽車合作,開發售價在100萬元的問界MPV,預計在2024年第2季度量產,銷量目標為上市首年交付5萬輛。
  • 微軟發布Windows 11新版 引入全新任務欄狀態

    近日,微軟發布了Windows 11新版,而Build 22563更新主要引入了幾周前曝光的平板模式任務欄等,系統更流暢了。更新中,Windows 11加入了專門針對平板優化的任務欄
Top 主站蜘蛛池模板: 长沙县| 财经| 九龙县| 芷江| 乐安县| 兴义市| 海林市| 辛集市| 普宁市| 岱山县| 诏安县| 江川县| 黎川县| 彭山县| 合肥市| 沧源| 大新县| 修文县| 连州市| 大丰市| 吉木乃县| 阳山县| 银川市| 东乡族自治县| 怀化市| 屯门区| 灵丘县| 永胜县| 天峨县| 安阳市| 丹阳市| 宁武县| 如皋市| 五峰| 卢湾区| 鄯善县| 尚义县| 忻州市| 兰考县| 荆州市| 水富县|