FyLib 2.5.2
dotnet add package FyLib --version 2.5.2
NuGet\Install-Package FyLib -Version 2.5.2
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="FyLib" Version="2.5.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FyLib" Version="2.5.2" />
<PackageReference Include="FyLib" />
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 FyLib --version 2.5.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FyLib, 2.5.2"
#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 FyLib@2.5.2
#: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=FyLib&version=2.5.2
#tool nuget:?package=FyLib&version=2.5.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
🚀 FyLib - 现代化 C# 工具库
FyLib 是一个功能丰富、性能卓越的现代化 C# 工具库,专为 .NET 10.0 设计,充分利用了最新的 C# 语言特性,为开发者提供高效、易用的常用功能集合。
✨ 核心优势
- .NET 10.0 专属设计,充分利用最新性能优化
- 扩展类型(Extension Types) 语法,提供更自然的 API 体验
- AOT 兼容,支持原生编译,启动更快、内存占用更少
- 可空引用类型,提供更安全的类型系统
- HTTP 客户端连接池复用,减少连接开销
AsSpan()等零分配技术,降低 GC 压力
📋 模块总览
| 模块 | 文件 | 功能描述 |
|---|---|---|
| 🔐 HashHelper | HashHelper.cs |
MD5、SHA1/256/384/512、HMAC、AES-256-CBC、RSA |
| 🌐 QuickHttp | Http/QuickHttp.cs |
HTTP 客户端,连接池、代理、HTTP/2、流式下载 |
| ⏰ TimeHelper | TimeHelper.cs |
UTC/本地时间戳、日期范围、时间段判断 |
| 📝 StringExtension | Ex/StringExtension.cs |
50+ 字符串扩展,验证、转换、格式化 |
| 🔢 BytesExtension | Ex/BytesExtension.cs |
字节数组扩展操作 |
| 📦 Pack / UnPack | Pack/ |
二进制数据打包与解包 |
| 🔁 AppAutoUpdate | AutoUpdate/ |
基于 JSON 清单的应用自动更新,MD5 校验 |
| 🗂️ IniHelper | FyLib/IniHelper.cs |
INI 配置文件读写 |
| 📁 FileExtensions | FyLib/FileExtensions.cs |
文件/目录操作扩展 |
| 🌍 IPHelper | FyLib/IPHelper.cs |
本地 IP 获取与网络信息 |
| 🖥️ RemoteProcess | FyLib/RemoteProcess.cs |
本地/远程进程管理 |
| 🔧 Other | Other.cs |
Ping、随机 MAC/IMEI、时间戳转换等杂项工具 |
| 📐 Kernel | Kernel/ |
DatetimeHelper、ObjectHelper、PathHelper |
| 🗺️ Map | FyLib/Map.cs |
有序键值对集合 |
| 🖱️ Windows API | API/ |
Kernel32、User32、ntdll、Shlwapi 封装 |
🎯 功能详解
🔐 HashHelper — 哈希与加密
// SHA 系列(推荐用于安全场景)
string hash256 = HashHelper.Sha256("data");
string hash512 = HashHelper.Sha512("data");
// HMAC 签名
string sig = HashHelper.HmacSha256("message", "secretKey");
// AES-256-CBC 加密 / 解密
string cipher = HashHelper.AesEncrypt("明文", "32字节长度的密钥字符串xxxxxxxxx");
string plain = HashHelper.AesDecrypt(cipher, "32字节长度的密钥字符串xxxxxxxxx");
// RSA 非对称加密
string encrypted = HashHelper.RsaEncrypt("data", publicKey);
string decrypted = HashHelper.RsaDecrypt(encrypted, privateKey);
// RSA 签名 / 验签
string sign = HashHelper.RsaSign("data", privateKey);
bool passed = HashHelper.RsaVerify("data", sign, publicKey);
🌐 QuickHttp — 现代 HTTP 客户端
// GET 请求 — 链式调用
string? html = await new QuickHttp("https://api.example.com/data")
.SetTimeout(5000)
.SetUserAgent("MyApp/1.0")
.AddQuery("page", "1")
.AddHeader("Authorization", "Bearer token")
.SetProxy("127.0.0.1", 8080)
.GetAsStringAsync();
// POST JSON 对象
var result = await new QuickHttp("https://api.example.com/submit")
.PostAsObjectAsync<MyResponse>(new { name = "FyLib", version = "2.5" });
// POST JToken
JToken resp = await new QuickHttp("https://api.example.com/json")
.PostAsJTokenAsync(JToken.Parse(@"{""key"":""value""}"));
// 上传文件(multipart/form-data)
await new QuickHttp("https://api.example.com/upload")
.PostFileAsync("/local/path/file.zip", formField: "file",
extraForm: new Dictionary<string, string> { ["desc"] = "文档" });
// 流式下载,带进度回调 + 自动重试(最多 3 次,指数退避)
bool ok = await new QuickHttp("https://example.com/large.zip")
.DownloadAsync(
savePath: "/tmp/large.zip",
onProgress: (downloaded, total) =>
{
if (total > 0)
Console.WriteLine($"进度:{downloaded * 100.0 / total:F1}%");
});
📝 StringExtension — 字符串扩展(.NET 10 Extension Types)
// 哈希 & 编码
string md5 = "hello".MD5; // 大写 MD5
string sha = "hello".Sha256; // SHA256
string crc = "hello".Crc32; // CRC32
string b64 = "hello".Base64; // Base64 编码
string plain = "aGVsbG8=".FromBase64; // Base64 解码
string enc = "a b".UrlEncode; // URL 编码
string he = "<p>".HtmlEncode; // HTML 编码
// 格式验证
bool isNum = "3.14".IsNumeric;
bool isIp = "192.168.1.1".IsIp;
bool isEmail = "a@b.com".IsEmail;
bool isPhone = "13812345678".IsPhone;
bool isId = "110101199001011234".IsIdCard;
bool isQQ = "123456".IsQQ;
bool isInt = "42".IsInt;
bool isFloat = "3.14".IsFloat;
bool isDt = "2024-01-01".IsDateTime;
// 字符串操作
string left = "Hello World".Left("World"); // "Hello "
string sub = "[content]".Between("[", "]"); // "content"
string rev = "abc".Reverse; // "cba"
string rep = "ab".Repeat(3); // "ababab"
string trunc = "很长的文本...".Truncate(5, "…");
// 大小写转换
string camel = "hello_world".ToCamelCase; // "helloWorld"
string pascal = "hello_world".ToPascalCase; // "HelloWorld"
string snake = "HelloWorld".ToSnakeCase; // "hello_world"
string kebab = "HelloWorld".ToKebabCase; // "hello-world"
// 隐私脱敏
string phone = "13812345678".MaskPhone; // "138****5678"
string email = "user@mail.com".MaskEmail; // "u***@mail.com"
string idcard = "110101...".MaskIdCard;
// 其他实用属性
bool hasCN = "你好 World".ContainsChinese;
int cnCnt = "你好 World".ChineseCount; // 2
int byteLen = "你好".ByteLength; // 6(UTF-8)
string digits = "abc123".OnlyDigits; // "123"
string letters = "abc123".OnlyLetters; // "abc"
byte[] raw = "48656C6C6F".ToBytes(); // Hex → byte[]
⏰ TimeHelper — 时间处理
int ts = TimeHelper.TimeStamp(); // UTC 十位时间戳
long tsMs = TimeHelper.TimeStampX(); // UTC 毫秒时间戳
var (start, end) = TimeHelper.GetStartEndTimestamps(ts); // 当天起止时间戳
bool inWork = TimeHelper.IsTimeInRange("09:00-18:00"); // 当前是否在范围内
// DateTime 扩展
int stamp = DateTime.Now.TimeStamp();
long stampMs = DateTime.Now.TimeStampX();
🔁 AppAutoUpdate — 应用自动更新
远程维护一份 JSON 更新清单,库自动完成差异下载和 MD5 校验:
var updater = new AppAutoUpdate("https://example.com/update.json");
// 检查是否有新版本
AppUpdateInfo? info = await updater.GetUpdateInfoAsync();
if (info != null)
Console.WriteLine($"最新版本:{info.Version}");
// 注册回调
updater.OnProgress = (file, cur, total) => Console.WriteLine($"[{cur}/{total}] {file}");
updater.OnDownloadProgress = (file, done, size) => Console.WriteLine($" {done}/{size} bytes");
updater.OnFileDownloaded = path => Console.WriteLine($"完成:{path}");
updater.OnError = (file, ex) => Console.WriteLine($"错误:{file} - {ex?.Message}");
updater.OnCompleted = () => Console.WriteLine("全部更新完成");
// 执行更新(缺失文件下载,MD5 不匹配自动重下)
await updater.UpdateAsync();
📦 Pack / UnPack — 二进制数据打包
using var pack = new Pack();
pack.push(42); // int
pack.push("hello"); // string
pack.push<byte>(255); // 泛型
byte[] data = pack.Get();
var unpack = new UnPack(data);
int n = unpack.pull<int>();
string s = unpack.pull<string>()!;
🔧 Other — 杂项工具
// 网络
bool alive = Other.Ping("8.8.8.8", 3000);
string mac = Other.GetRandMac(); // 随机 MAC 地址
string imei = Other.GetRandImei(); // 随机 IMEI
// 时间戳转换
string dt = Other.TimeStampToString(TimeHelper.TimeStamp());
int ts = Other.StringToTimeStamp("2024-01-01 00:00:00");
// 其他
int ms = Other.GetRunningTime(); // 程序运行时长(毫秒)
Other.Sleep(500);
🚀 快速开始
安装
# .NET CLI
dotnet add package FyLib
# Package Manager Console
Install-Package FyLib
# PackageReference
<PackageReference Include="FyLib" Version="2.5.0" />
最低要求
- .NET 10.0 或更高版本
- C# 13.0(Extension Types 语法)
- 支持 Windows、Linux、macOS
- AOT 原生编译兼容
🎯 适用场景
- ✅ Web API 开发 — HTTP 客户端、JSON 处理、数据加解密
- ✅ 数据处理 — 字符串解析、格式验证、编码转换
- ✅ 安全相关 — AES 加密、RSA 签名、HMAC 认证
- ✅ 网络编程 — TCP/UDP 数据包打包、多协议 HTTP 请求
- ✅ 配置管理 — INI 文件读写
- ✅ 文件操作 — 路径处理、文件读写、流式下载
- ✅ 应用分发 — 内置自动更新框架,支持增量更新
- ✅ 性能敏感应用 — AOT 编译、连接池、零分配技术
📄 许可证
Copyright © 枫影傲然 2024 - MIT License
🔗 相关链接
⭐ 如果这个项目对你有帮助,请给个 Star 支持一下!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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
- Newtonsoft.Json (>= 13.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on FyLib:
| Package | Downloads |
|---|---|
|
FyLib.DuckSoft.ClientApi
DuckClient API 客户端 SDK,提供用户认证、版本管理、会话管理、支付集成、SignalR 实时通信等功能。开箱即用,自动加密签名,轻松对接 DuckClient SaaS 平台。 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 2.5.2 | 135 | 2/27/2026 | |
| 2.5.1 | 142 | 2/27/2026 | |
| 2.5.0 | 143 | 2/25/2026 | |
| 2.4.0 | 296 | 12/15/2025 | |
| 2.2.0 | 225 | 9/25/2025 | |
| 2.1.0 | 311 | 9/25/2025 | |
| 2.0.0 | 305 | 8/7/2025 | |
| 1.2.0 | 213 | 1/13/2025 | |
| 1.1.9 | 206 | 1/11/2025 | |
| 1.1.8 | 229 | 1/11/2025 | |
| 1.1.7 | 246 | 12/12/2024 | |
| 1.1.6 | 209 | 12/12/2024 | |
| 1.1.5 | 221 | 12/7/2024 | |
| 1.1.4 | 234 | 8/27/2024 | |
| 1.1.3 | 217 | 7/16/2024 | |
| 1.1.1 | 238 | 5/5/2024 | |
| 1.1.0 | 312 | 12/26/2023 |
Loading failed