XYS.Utils.Sys
2.3.3
See the version list below for details.
dotnet add package XYS.Utils.Sys --version 2.3.3
NuGet\Install-Package XYS.Utils.Sys -Version 2.3.3
<PackageReference Include="XYS.Utils.Sys" Version="2.3.3" />
<PackageVersion Include="XYS.Utils.Sys" Version="2.3.3" />
<PackageReference Include="XYS.Utils.Sys" />
paket add XYS.Utils.Sys --version 2.3.3
#r "nuget: XYS.Utils.Sys, 2.3.3"
#:package XYS.Utils.Sys@2.3.3
#addin nuget:?package=XYS.Utils.Sys&version=2.3.3
#tool nuget:?package=XYS.Utils.Sys&version=2.3.3
XYS.Utils.Sys
系统级通用工具类库:HTTP/JSON 调用、文件、类型转换、反射、XML、邮件、CSV 导出、数据库映射辅助与配置读取等。
目标框架
net8.0 · net462 · netcoreapp3.1 · netstandard2.0 · netstandard2.1
依赖
- Newtonsoft.Json
13.0.4 - Microsoft.CSharp
4.7.0 - XYS(同解决方案内项目引用)
HttpJsonUtil
基于 HttpClient 的 JSON 请求工具,提供 POST / GET 并自动反序列化响应,支持 HTTPS。
using XYS.Utils.Sys;
// POST:对象自动序列化为 JSON,反序列化为指定类型
var res = HttpJsonUtil.Post<ResultDto>("https://api.example.com/order", new { id = 1 }, timeout: 5000);
// GET
var dto = HttpJsonUtil.Get<ResultDto>("https://api.example.com/order/1");
// 带 Cookie / 自定义 UserAgent
var res2 = HttpJsonUtil.Post("https://api.example.com/x", req, timeout: 3000, userAgent: "MyApp", cookies: myCookies);
- HTTPS:静态构造时自动启用 TLS 1.2/1.1(兼容 net462 等旧框架访问现代 HTTPS 服务;.NET Core/5+ 由系统协商,无副作用)。
- 证书校验:
HttpJsonUtil.AllowUntrustedCertificate默认true,放行自签名/内网证书;生产环境建议置为false以启用标准 TLS 校验,防止中间人攻击。 timeout单位毫秒。无 Cookie 时复用静态HttpClient;带 Cookie 时创建独立实例并自动释放。
需要按
baseUrl复用客户端、请求级超时隔离与 Token 注入的高并发场景,参见XYS.Utils.Web中的HttpRestUtil。
NovaWebClient
基于 HttpClient 的下载客户端(IDisposable),支持"无数据接收即超时取消"的文件下载。
using XYS.Utils.Sys;
using (var client = new NovaWebClient { Timeout = 5000 }) // 毫秒
{
byte[] data = client.DownloadData("https://.../file.bin");
string text = client.DownloadString("https://.../data.json");
client.TimeOver += token => { /* 超时回调 */ };
client.DownloadFileAsyncWithTimeout(new Uri("https://.../big.zip"), "big.zip", null);
}
Timeout单位为毫秒,作为每次读取的空闲超时;在超时时间内无任何数据到达则自动取消。- 用完请
Dispose(或using)以释放内部HttpClient。
TypeExtension
常用类型扩展方法。
using XYS.Utils.Sys;
string json = anyObject.ToJson(); // 序列化为 JSON
int? n = "123".ToInt(); // 安全转 int?
DateTime? d = "2026-07-21".ToDateTime(); // 安全转 DateTime?
string xml = raw.ToXmlStr(); // XML 特殊字符转义
ToJson / ToInt / ToFloat / ToDouble / ToDecimal / ToDateTime / ToSmallDateTime / ToXmlStr 等,均对 null/非法输入做安全处理。
FileUtil
文件与目录辅助:
File2Bytes(fullFileName)— 读取文件为字节数组GetFullName(params paths)— 拼接路径MakeDir(filePath)— 创建目录IsFileExist/IsDictExist/DeleteFile/DeleteDict
ConvertUtil
安全类型转换:TryParse 的 int / long / short 重载,转换失败返回 false 且不抛异常。
ReflexUtil
反射辅助:AssemblyShortName / AssemblyFileName / GetTypeFromString(按类型名解析 Type)。
XmlUtil
XML 辅助:TypeConvert(input, type) 按目标类型转换字符串,DefaultForType(type) 返回类型默认值。
MailHelper
邮件发送:MailHelper.SendMail(MailRequest request),MailRequest 支持正文、收件人及 MailRequestAttachments 附件。
ExportHelper
CSV 导出:ExportCVS(fileName, rows, csvSeparator = ',', coding = null),rows 为 List<List<string>>。
SystemInfo
配置读取与系统辅助(配置文件 xys.config.json,读取后缓存):
GetAppSetting(key)/GetConfigValue(key)— 读取配置项GetConnString(name)/GetConnStruct(name)— 读取数据库连接串ReloadConfig()— 重新加载配置- 另含 GUID、日期格式化、路径、类型判断等杂项工具。
DB(数据库映射辅助)
配合 DBColAttribute + 反射实现实体与数据行/存储过程参数的映射:
DBUtil.Convert/DeConvert— 实体与数据源对象互转DBHelper— 存储过程入/出参装配、DB 值与类型解析DBParse— 安全取值(GetSafeInt/GetSafeDate/GetSafeDecimal/GetSafeStr等)NConvert— 数值/日期/布尔转换,含金额转大写ToCapitalSqlUtil.GetWhere(paramDict, tableAlias)— 由字典拼接 WHERE 条件
版本
当前版本 2.3.3。
| 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 3.1
- Microsoft.CSharp (>= 4.7.0)
- Newtonsoft.Json (>= 13.0.4)
- XYS (>= 2.3.1)
-
.NETFramework 4.6.2
- Microsoft.CSharp (>= 4.7.0)
- Newtonsoft.Json (>= 13.0.4)
- XYS (>= 2.3.1)
-
.NETStandard 2.0
- Microsoft.CSharp (>= 4.7.0)
- Newtonsoft.Json (>= 13.0.4)
- XYS (>= 2.3.1)
-
.NETStandard 2.1
- Microsoft.CSharp (>= 4.7.0)
- Newtonsoft.Json (>= 13.0.4)
- XYS (>= 2.3.1)
-
net8.0
- Microsoft.CSharp (>= 4.7.0)
- Newtonsoft.Json (>= 13.0.4)
- XYS (>= 2.3.1)
NuGet packages (19)
Showing the top 5 NuGet packages that depend on XYS.Utils.Sys:
| Package | Downloads |
|---|---|
|
XYS.FR
Package Description |
|
|
XYS.DataFactory
Package Description |
|
|
XYS.Utils.DB
Package Description |
|
|
XYS.Utils.Web
Package Description |
|
|
XYS.Mongo
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.6.0 | 147 | 7/25/2026 |
| 2.5.0 | 306 | 7/22/2026 |
| 2.3.3 | 185 | 7/21/2026 |
| 2.3.2 | 149 | 7/16/2026 |
| 2.3.1 | 189 | 7/14/2026 |
| 2.2.1.4 | 266 | 1/7/2026 |
| 2.2.1.2 | 893 | 12/7/2023 |
| 2.2.1.1 | 583 | 12/4/2023 |
| 2.1.2.1 | 576 | 11/24/2023 |
| 2.1.1.2 | 270 | 10/27/2023 |
| 2.1.1.1 | 568 | 5/15/2023 |
| 2.1.0.10 | 439 | 2/13/2023 |
| 2.1.0.9 | 573 | 2/8/2023 |
| 2.1.0.8 | 478 | 2/1/2023 |
| 2.1.0.7 | 475 | 2/1/2023 |
| 2.1.0.6 | 507 | 1/18/2023 |
| 2.1.0.5 | 503 | 1/18/2023 |
| 2.1.0.4 | 6,117 | 6/7/2022 |
| 2.1.0.3 | 2,730 | 5/7/2022 |