BugFree.Core
1.2.2026.613-beta1539
This is a prerelease version of BugFree.Core.
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package BugFree.Core --version 1.2.2026.613-beta1539
NuGet\Install-Package BugFree.Core -Version 1.2.2026.613-beta1539
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="BugFree.Core" Version="1.2.2026.613-beta1539" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BugFree.Core" Version="1.2.2026.613-beta1539" />
<PackageReference Include="BugFree.Core" />
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 BugFree.Core --version 1.2.2026.613-beta1539
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: BugFree.Core, 1.2.2026.613-beta1539"
#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 BugFree.Core@1.2.2026.613-beta1539
#: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=BugFree.Core&version=1.2.2026.613-beta1539&prerelease
#tool nuget:?package=BugFree.Core&version=1.2.2026.613-beta1539&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
BugFree.Core
📖 项目介绍
BugFree.Core 是 .NET 工具类库,提供编解码、枚举、集合、IP、路径安全、单位格式化等扩展方法,以及安全随机串生成、资源压力测试等工具,助力高效开发。
🎯 功能特性
扩展方法(Extensions)
| 类名 | 说明 |
|---|---|
| AttributeExtensions | 通过字段名字符串获取自定义特性(Attribute),支持 TryGet 模式 |
| CodecExtensions | 编解码工具集:Hex、Base32、Base58、Base64、Base64Url、Base91 编码转换 |
| EnumerableExtensions | 集合扩展:判断空集合、ForEach 遍历、AddRange 批量添加(自动优化 List<T>) |
| DictionaryExtensions | 线程安全的字典 TryGetOrAdd 方法,兼容 ConcurrentDictionary |
| EnumExtensions | 枚举扩展:获取枚举值的 Description 描述信息,支持批量获取 |
| IpConvertExtensions | IP 地址工具:IPv4 ↔ UInt32 互转、CIDR 网段解析 |
| PathSecurityHelper | 路径安全防护:防止路径穿越攻击、规范化路径片段、路径合法性校验 |
| TcpClientExtensions | TCP 连接状态可靠检测,解决 Socket.Connected 误判问题 |
| UnitFormatExtensions | 数值单位格式化:存储容量(B/KB/MB/GB...)、传输速率、频率、操作速率、请求速率、中文万/亿/兆等 |
特性(Attributes)
| 类名 | 说明 |
|---|---|
| DisplayAttribute | UI 显示元数据特性,支持名称、短名称、分组、说明、提示语和排序 |
工具类(Tools)
| 类名 | 说明 |
|---|---|
| ResourceStressController | 系统资源压力控制器,模拟 CPU/内存/磁盘高负载,用于性能测试 |
| SecureRandomStringGenerator | 密码学安全随机字符串生成器,支持数字、字母、符号等多种字符集,可排除易混淆字符 |
🚀 快速开始
安装
通过 NuGet 安装:
dotnet add package BugFree.Core
或者通过包管理器控制台:
Install-Package BugFree.Core
使用示例
// 1. 编解码
using BugFree.Core.Extensions;
byte[] data = "Hello World".GetBytes();
string hex = data.ToHex(); // "48656c6c6f20576f726c64"
string base64 = data.ToBase64(); // "SGVsbG8gV29ybGQ="
// 2. 枚举描述
enum Status { [Description("正常")] Active, [Description("已禁用")] Disabled }
string desc = Status.Active.GetDescription(); // "正常"
// 3. 单位格式化
long fileSize = 2_147_483_648;
string formatted = fileSize.UnitFormatSize(UnitFormatExtensions.UnitKind.Storage);
// 输出: "2.00 GB"
// 4. 路径安全
string safePath = PathSecurityHelper.NormalizePart("user/avatar.png");
// 拒绝 "../etc/passwd" 等路径穿越输入
// 5. 随机字符串
var options = new RandomStringOptions
{
Length = 8,
Kind = RandomStringKind.Alphanumeric,
ExcludeConfusingCharacters = true
};
string code = SecureRandomStringGenerator.Generate(options);
// 6. IP 地址转换
if ("192.168.1.1".TryToIpUInt32(out uint ipValue)) { }
var (network, mask) = "10.0.0.0/24".ToCidrNetwork();
// 7. 集合操作
new[] { 1, 2, 3 }.ForEach(x => Console.WriteLine(x));
list.AddRange(otherItems);
// 8. 特性获取
typeof(MyEnum).GetFieldAttribute<DescriptionAttribute>("FieldName");
📦 项目结构
BugFree.Core/
├── Attributes/ # 自定义特性
│ └── DisplayAttribute.cs
├── Extensions/ # 扩展方法
│ ├── AttributeExtensions.cs # 字段特性扩展
│ ├── CodecExtensions.cs # 编解码扩展
│ ├── CollectionExtensions.cs # 集合扩展
│ ├── DictionaryExtensions.cs # 字典扩展
│ ├── EnumExtensions.cs # 枚举扩展
│ ├── IpConvertExtensions.cs # IP 地址转换
│ ├── PathSecurityHelper.cs # 路径安全防护
│ ├── TcpClientExtensions.cs # TCP 连接检测
│ └── UnitFormatExtensions.cs # 单位格式化
└── Tools/ # 工具类
├── ResourceStressController.cs # 资源压力测试
└── SecureRandomStringGenerator.cs # 安全随机字符串
🛠️ 技术要求
- .NET 8.0 / .NET 10.0
- C# 最新语言版本
- 支持 Windows / Linux 跨平台
🤝 参与贡献
- Fork 本仓库
- 新建特性分支 (
git checkout -b feature/xxx) - 提交代码 (
git commit -m '添加xxx功能') - 推送到分支 (
git push origin feature/xxx) - 新建 Pull Request
📄 开源协议
本项目基于 MIT 协议开源,详见 LICENSE 文件。
📮 联系我们
- 作者:IoTHub开发团队
- Gitee:https://gitee.com/BugFree_1/BugFree.Core
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- System.Diagnostics.PerformanceCounter (>= 10.0.8)
-
net8.0
- System.Diagnostics.PerformanceCounter (>= 10.0.8)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on BugFree.Core:
| Package | Downloads |
|---|---|
|
BugFree.Security
安全加密框架,集成 BCrypt/Argon2/Scrypt/BouncyCastle 等现代密码学算法,提供哈希、签名、加解密及随机数生成服务。 |
|
|
BugFree.Controllers.Api
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.2026.703-beta1428 | 59 | 7/3/2026 |
| 1.2.2026.702-beta1632 | 60 | 7/2/2026 |
| 1.2.2026.614-beta1516 | 212 | 6/14/2026 |
| 1.2.2026.613-beta1539 | 123 | 6/13/2026 |
| 1.1.260612-beta1733 | 69 | 6/12/2026 |
| 1.1.2026.612-beta1740 | 81 | 6/12/2026 |
| 1.1.2026.309-beta1157 | 87 | 3/9/2026 |
| 1.1.2026.309-beta1155 | 66 | 3/9/2026 |
| 1.1.2026.309-beta1145 | 69 | 3/9/2026 |
| 1.1.2026.126-beta1023 | 80 | 1/26/2026 |
| 1.1.2026.121-beta1049 | 133 | 1/21/2026 |
| 1.0.2026.115-beta1509 | 161 | 1/15/2026 |
| 1.0.2026.115-beta1458 | 83 | 1/15/2026 |
| 1.0.2026.115-beta1306 | 118 | 1/15/2026 |
| 1.0.2026.115-beta1248 | 75 | 1/15/2026 |
| 1.0.2026.115-beta1229 | 80 | 1/15/2026 |