AVt天堂网 手机版,亚洲va久久久噜噜噜久久4399,天天综合亚洲色在线精品,亚洲一级Av无码毛片久久精品

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

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

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

前言

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

直接項目引入類庫使用

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

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

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

項目源代碼

圖片圖片vUi28資訊網——每日最新資訊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/vUi28資訊網——每日最新資訊28at.com

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

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

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

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

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

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

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

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

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

標簽:
  • 熱門焦點
  • Mate60手機殼曝光 致敬自己的經典設計

    8月3日消息,今天下午博主數碼閑聊站帶來了華為Mate60的第三方手機殼圖,可以讓我們在真機發布之前看看這款華為全新旗艦的大致輪廓。從曝光的圖片看,Mate 60背后攝像頭面積依然
  • 小米降噪藍牙耳機Necklace分享:聽一首歌 讀懂一個故事

    在今天下午的小米Civi 2新品發布會上,小米還帶來了一款新的降噪藍牙耳機Necklace,我們也在發布結束的第一時間給大家帶來這款耳機的簡單分享。現在大家能見到最多的藍牙耳機
  • 6月安卓手機好評榜:魅族20 Pro蟬聯冠軍

    性能榜和性價比榜之后,我們來看最后的安卓手機好評榜,數據來源安兔兔評測,收集時間2023年6月1日至6月30日,僅限國內市場。第一名:魅族20 Pro好評率:95%5月份的時候魅族20 Pro就是
  • Golang 中的 io 包詳解:組合接口

    io.ReadWriter// ReadWriter is the interface that groups the basic Read and Write methods.type ReadWriter interface { Reader Writer}是對Reader和Writer接口的組合,
  • 得物寵物生意「狂飆」,發力“它經濟”

    作者|花花小萌主近日,得物宣布正式上線寵物鑒別,通過得物App內的&ldquo;在線鑒別&rdquo;,可找到鑒別寵物的選項。通過上傳自家寵物的部位細節,就能收獲擁有專業資質認證的得物鑒
  • 新電商三兄弟,“抖快紅”成團!

    來源:價值研究所作 者:Hernanderz 隨著內容電商的概念興起,抖音、快手、小紅書組成的&ldquo;新電商三兄弟&rdquo;成為業內一股不可忽視的勢力,給阿里、京東、拼多多帶去了巨大壓
  • 微博大門常打開,迎接海外畫師漂洋東渡

    作者:互聯網那些事&ldquo;起猛了,我能看得懂日語了&rdquo;。&ldquo;為什么日本人說話我能聽懂?&rdquo;&ldquo;中文不像中文,日語不像日語,但是我竟然看懂了&rdquo;&hellip;&hell
  • 2納米決戰2025

    集微網報道 從三強爭霸到四雄逐鹿,2nm的廝殺聲已然隱約傳來。無論是老牌勁旅臺積電、三星,還是誓言重回先進制程領先地位的英特爾,甚至初成立不久的新
  • 外交部:美方應停止在網絡安全問題上不負責任地指責他國

      中國外交部今天(16日)舉行例行記者會。會上,有記者問,美國情報官員稱,他們正在阻攔來自中國以及其他國家的黑客獲取相關科研成果。 中方對此有何評論?對此
Top