Chet.Utils
1.6.0
.NET 8.0
This package targets .NET 8.0. The package is compatible with this framework or higher.
.NET Standard 2.1
This package targets .NET Standard 2.1. The package is compatible with this framework or higher.
dotnet add package Chet.Utils --version 1.6.0
NuGet\Install-Package Chet.Utils -Version 1.6.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Chet.Utils" Version="1.6.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Chet.Utils" Version="1.6.0" />
<PackageReference Include="Chet.Utils" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Chet.Utils --version 1.6.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Chet.Utils, 1.6.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Chet.Utils@1.6.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Chet.Utils&version=1.6.0
#tool nuget:?package=Chet.Utils&version=1.6.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Chet.Utils
概述
Chet.Utils 是一个为 .NET 开发提供全面辅助工具的类库。该项目旨在简化代码编写过程中的常见操作,提高开发效率,减少重复代码。所有扩展方法和帮助类都经过精心设计,遵循 .NET 最佳实践,提供完整的 XML 文档注释。
特性
- 🚀 高性能 - 经过优化的实现,减少不必要的内存分配
- 🔒 安全可靠 - 完善的空值检查和异常处理
- 📖 完整文档 - 所有方法都有详细的 XML 注释和使用示例
- 🧪 单元测试 - 核心功能都有对应的单元测试覆盖
- 🎯 易于使用 - 直观的 API 设计,符合 .NET 命名规范
主要功能
扩展方法
| 扩展类 | 说明 | 详细文档 |
|---|---|---|
| BoolExtensions | Bool 扩展方法,提供基础判断、逻辑运算、类型转换、条件执行等功能 | 查看详情 |
| DataTableExtensions | DataTable 扩展方法,提供数据转换、查询、操作、序列化等功能 | 查看详情 |
| DateTimeExtensions | DateTime 扩展方法,提供日期判断、格式化、计算、转换等功能 | 查看详情 |
| DecimalExtensions | decimal 扩展方法,提供数值判断、数学运算、格式化、类型转换等功能 | 查看详情 |
| DoubleExtensions | double 扩展方法,提供数值判断、数学运算、格式化、类型转换等功能 | 查看详情 |
| EnumExtensions | Enum 扩展方法,提供枚举判断、转换、描述获取、标志操作等功能 | 查看详情 |
| EnumerableExtensions | IEnumerable/ICollection 扩展方法,提供集合判断、转换、分页、统计等功能 | 查看详情 |
| FileExtensions | 文件扩展方法,提供文件读写、判断、信息获取、哈希计算等功能 | 查看详情 |
| FloatExtensions | float 扩展方法,提供数值判断、数学运算、格式化、类型转换等功能 | 查看详情 |
| IntExtensions | int 扩展方法,提供数值判断、数学运算、格式化、中文转换等功能 | 查看详情 |
| StreamExtensions | Stream 扩展方法,提供流读写、转换、压缩、哈希计算等功能 | 查看详情 |
| StringExtensions | string 扩展方法,提供空值判断、正则验证、类型转换、编码解码等功能 | 查看详情 |
帮助类
| 帮助类 | 说明 | 详细文档 |
|---|---|---|
| ApplicationHelper | 应用程序帮助类,提供进程管理、内存优化、系统信息获取等功能 | 查看详情 |
| DataTableHelper | 数据表帮助类,提供数据透视、数据分析、数据清洗等高级功能 | 查看详情 |
| FileHelper | 文件帮助类,提供文件监控、临时文件管理、文件比较等高级功能 | 查看详情 |
| HttpClientHelper | HTTP 客户端帮助类,提供重试机制、超时控制、认证管理等功能 | 查看详情 |
| ReflectHelper | 反射帮助类,提供类型检查、属性操作、方法调用、表达式树等功能 | 查看详情 |
| RegexHelper | 正则表达式帮助类,提供常用验证、匹配、替换、提取等功能 | 查看详情 |
| StopwatchHelper | 计时帮助类,提供高精度计时、性能统计、基准测试等功能 | 查看详情 |
| TaskHelper | 任务帮助类,提供超时控制、重试机制、并行处理、任务调度等功能 | 查看详情 |
| UnitHelper | 单位帮助类,提供长度、货币、质量、角度等多种单位转换功能 | 查看详情 |
| WebSocketHelper | WebSocket 帮助类,提供客户端/服务端连接管理、消息收发、心跳检测等功能 | 查看详情 |
安装
NuGet 包管理器
Install-Package Chet.Utils
.NET CLI
dotnet add package Chet.Utils
PackageReference
<PackageReference Include="Chet.Utils" Version="1.6.0" />
快速开始
使用扩展方法
using Chet.Utils;
// 字符串扩展
string email = "test@example.com";
bool isValid = email.IsEmail(); // true
// 日期扩展
DateTime date = DateTime.Now;
bool isWeekend = date.IsWeekend(); // 判断是否周末
string formatted = date.ToChineseDateString(); // "二〇二四年一月一日"
// 集合扩展
var list = new List<int> { 1, 2, 3, 4, 5 };
var page = list.GetPage(1, 2); // 分页获取数据
bool isEmpty = list.IsNullOrEmpty(); // 判断是否为空
// 数值扩展
int value = 12345;
string thousands = value.ToThousandsString(); // "12,345"
string chinese = value.ToChineseNumber(); // "一万二千三百四十五"
使用帮助类
using Chet.Utils.Helpers;
// HTTP 客户端
var httpHelper = new HttpClientHelper();
var response = await httpHelper.GetAsync<string>("https://api.example.com/data");
// 正则表达式
bool isPhone = RegexHelper.IsMobilePhone("13800138000");
var emails = RegexHelper.ExtractEmails("联系邮箱: test@example.com");
// 计时器
var elapsed = StopwatchHelper.Measure(() =>
{
// 要测试的代码
});
Console.WriteLine($"执行时间: {elapsed.TotalMilliseconds}ms");
// WebSocket 客户端
var wsClient = new WebSocketHelper();
wsClient.OnMessageReceived += (sender, e) => Console.WriteLine(e.Message);
await wsClient.ConnectAsync(new Uri("ws://localhost:8080"));
await wsClient.SendMessageAsync("Hello, World!");
系统要求
- .NET 8.0 或更高版本(推荐)
- .NET Standard 2.1(完整功能,含 polyfill 兼容层)
版本更新
v1.6.0 (当前版本)
新功能
- ✨ 优化 DataTableHelper 类,添加更多功能
- 🔧 优化 DataTableExtensions、EnumExtensions、EnumerableExtensions、StreamExtensions 等扩展类
- 🌐 新增
netstandard2.1+net8.0双目标框架支持,旧框架消费方可直接升级 - 📦 引入 Polyfills 模块(
ThrowHelper、ParallelHelper、HttpContent/HashAlgorithm扩展方法),统一不同目标下的 API 行为 - 🔧 修复多目标构建中暴露的 .NET 6+/7+ API 依赖(
ArgumentException.ThrowIfNullOrEmpty、Convert.ToHexString、TimeSpan.TotalMicroseconds/TotalNanoseconds、Stopwatch.GetElapsedTime、Environment.ProcessId/TickCount64、GC.GetGCMemoryInfo、Parallel.ForEachAsync/ForAsync、ValueTask.FromResult、StringSplitOptions.TrimEntries等) - 🔧
StreamReader构造器统一使用 5 参数形式,跨目标兼容 - 🔧
ApplicationHelper.GetAvailableMemory在 netstandard2.1 上回退至GC.GetTotalMemory
v1.5.0
新功能
重构所有扩展类和帮助类,使其更通用、更易用
v1.4.0
新增功能
- ✨ 添加 WebSocket 帮助类,包含客户端和服务端实现
- 支持连接管理、消息收发、心跳检测、自动重连
- 支持消息队列、广播、组播等功能
- ✨ StringExtensions 类扩展了部分方法
改进
- 📝 完善所有扩展类和帮助类的 XML 文档注释
- 📝 更新所有功能文档,添加详细的使用示例
- 🔧 优化代码结构,提高代码可读性
v1.3.0
新增功能
- ✨ 添加 ApplicationHelper 应用程序帮助类
- ✨ 添加 ReflectHelper 反射帮助类
- ✨ 添加 StopwatchHelper 计时帮助类
- ✨ 添加 TaskHelper 任务帮助类
- ✨ 添加 UnitHelper 单位帮助类
v1.2.0
新增功能
- ✨ 添加 DataTableHelper 数据表帮助类
- ✨ 添加 FileHelper 文件帮助类
- ✨ 添加 RegexHelper 正则表达式帮助类
v1.1.0
新增功能
- ✨ 添加 HttpClientHelper HTTP 客户端帮助类
- ✨ 完善扩展方法类
v1.0.0
初始版本
- 🎉 基础扩展方法类(Bool、DateTime、Decimal、Double、Float、Int、String、Enumerable)
- 🎉 基础帮助类
贡献指南
欢迎提交 Issue 和 Pull Request 来帮助改进这个项目。
许可证
本项目采用 MIT 许可证。详见 LICENSE 文件。
联系方式
如有问题或建议,请通过以下方式联系:
- 提交 GitHub Issue
- 发送邮件至:qctvip@vip.163.com
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- Microsoft.CSharp (>= 4.7.0)
- Microsoft.Extensions.Logging (>= 8.0.1)
- Newtonsoft.Json (>= 13.0.3)
- System.Net.Http (>= 4.3.4)
- System.Security.Principal.Windows (>= 5.0.0)
- System.Text.Json (>= 8.0.5)
- System.Threading.Channels (>= 8.0.0)
-
net8.0
- Microsoft.Extensions.Logging (>= 9.0.10)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.