Xunet 1.0.10
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Framework 4.5
This package targets .NET Framework 4.5. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Xunet --version 1.0.10
NuGet\Install-Package Xunet -Version 1.0.10
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="Xunet" Version="1.0.10" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Xunet --version 1.0.10
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Xunet, 1.0.10"
#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.
// Install Xunet as a Cake Addin #addin nuget:?package=Xunet&version=1.0.10 // Install Xunet as a Cake Tool #tool nuget:?package=Xunet&version=1.0.10
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
常用工具库
Xunet 是 .NET 的通用工具库,包含扩展方法、辅助类和一些常用组件,用于简化开发和提高工作效率。
支持 .NET Framework 4.5、.NET 6.0、.NET 7.0
扩展类
1、日期时间扩展类
// 获取当前时间戳
var timeStamp = DateTime.Now.ToTimeStamp();
// 时间戳转DateTime
var dateTime = timeStamp.ToDateTime();
2、Ffmpeg扩展类
// 音频文件路径
var audio_path = "音频文件路径";
// 获取音频文件时长
var length = audio_path.GetMediaLength("Ffmpeg.exe所在目录,默认当前目录");
// 视频文件路径
var video_path = "视频文件路径";
// 获取视频截图
var image = video_path.CatchVideoImg("目标存储路径", "Ffmpeg.exe所在目录,默认当前目录");
3、HttpClient扩展类
// 接口地址
var url = "https://api.demo.com/test";
// GET请求
var result = await url.HttpGetAsync();
// POST请求(支持application/json和form-data)
var result2 = await url.HttpPostAsync(HttpContentType.ApplicationJson,
new { id = "参数1", name = "参数2" });
// PUT请求(支持application/json和form-data)
var result2 = await url.HttpPutAsync(HttpContentType.ApplicationJson,
new { id = "参数1", name = "参数2" });
// DELETE请求
var result = await url.HttpDeleteAsync();
4、Json扩展类
// object对象
var data = new { code = 0, message = "" };
// JSON序列化
var json = data.SerializeObject();
// JSON反序列化
var obj = json.DeserializeObject<object>();
5、随机数扩展类
// 获取0~10以内的随机数(方式一)
var randomNum1 = 0.Next(10);
// 获取0~10以内的随机数(方式二)
var randomNum2 = 10.Next();
// 获取8位数随机字符串
// 参数:level,复杂等级,0纯数字,1数字+字母,2数字+字母+特殊字符
var randomText = 8.NextString(2);
6、加解密扩展类
// 输入字符串
var input = "123456";
// MD5加密
var md5Value = input.ToMD5Encrypt();
// SHA256加密
var sha256Value = input.ToSHA256Encrypt();
// AES加密
var aesValue = input.ToAESEncrypt();
// AES解密
var aesText = aesValue.ToAESDecrypt();
// RSA加密
// 获取RSA公钥和私钥(2048位)
var key = 2048.ToRSASecretKey();
// 公钥加密
var rsaValue = input.ToRSAEncrypt(key.PublicKey);
// 私钥解密
var rsaText = rsaValue.ToRSADecrypt(key.PrivateKey);
7、String扩展类
// 输入字符串
var input = "123456";
// 判断是否是null或者空字符串
var isNull = input.IsNullOrEmpty();
// 判断是否非null且非空字符串
var isNotNull = input.IsNotNullOrEmpty();
// 判断是否是手机号
var isTel = input.IsPhoneNumber();
// ...
8、反射扩展类
// 对象
var user = new User { Name = "徐来" };
// 获取Name属性
var name = user.GetProperty<string>("Name");
// 设置Name属性
var namenew = user.SetProperty("Name", "徐来new");
9、异常处理扩展类
var result = typeof(TestClass).TryCatch(
(x) =>
{
// 主要业务逻辑
},
(x) =>
{
// 异常处理
},
(x) =>
{
// 执行成功
});
typeof(TestClass).TryFinally(
(x) =>
{
// 主要业务逻辑
},
(x) =>
{
// finally处理
});
辅助类
1、雪花ID
// 雪花Id(long类型)
var id1 = SnowflakeHelper.NextId();
// 雪花Id(字符串)
var id2 = SnowflakeHelper.NextIdString();
2、拼音助手
// 获取中文全拼
var pinyin = PinyinHelper.GetPinyin("徐来");
3、读取配置文件
// 获取配置
var value = AppSettingsHelper.GetValueOrDefault("key");
4、性能计时器
var milliSeconds = StopwatchHelper.Execute(() =>
{
// do something
Thread.Sleep(100);
});
5、数据计算
// 获取两个坐标的距离
var distance = MathHelper.GetDistance(1, 2, 3, 4);
6、IP转地区
// 说明:仅支持.NET 6.0 及以上版本
// 需要依赖ip2region.xdb文件
// https://github.com/lionsoul2014/ip2region/blob/master/data/ip2region.xdb
// 根据IP查询地区
var region = IP2RegionHelper.Search("ip地址");
组件
1、日志组件
LogManager.Info("这是一条测试日志");
2、缓存组件
// 使用CSRedis;
using Xunet.CSRedis;
// 初始化Redis缓存
RedisHelper.Initialization(new CSRedis.CSRedisClient("127.0.0.1:6379"));
// 设置缓存
await RedisHelper.SetAsync("user", new User { Name = "徐来" });
// 获取缓存
var user = await RedisHelper.GetAsync<User>("user");
3、ORM组件
// 使用Dapper
using Xunet.Dapper;
// 查询
var list = await connection.QueryAsync<User>("select * from user;");
感谢
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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 is compatible. 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 was computed. 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. |
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.5
- System.ValueTuple (>= 4.5.0)
-
net6.0
- Microsoft.AspNetCore (>= 2.2.0)
-
net7.0
- Microsoft.AspNetCore (>= 2.2.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Xunet:
Package | Downloads |
---|---|
Xunet.WinFormium
A Lightweight WinForm Application Framework For .NET |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.23 | 139 | 8/16/2024 |
1.0.22 | 134 | 7/3/2024 |
1.0.21 | 98 | 6/28/2024 |
1.0.20 | 86 | 6/25/2024 |
1.0.19 | 125 | 4/10/2024 |
1.0.18 | 132 | 12/15/2023 |
1.0.17 | 133 | 11/28/2023 |
1.0.16 | 135 | 11/27/2023 |
1.0.15 | 120 | 11/27/2023 |
1.0.14 | 147 | 8/8/2023 |
1.0.13 | 167 | 8/7/2023 |
1.0.12 | 190 | 7/13/2023 |
1.0.11 | 161 | 7/4/2023 |
1.0.10 | 172 | 6/12/2023 |
1.0.9 | 160 | 6/8/2023 |
1.0.8 | 174 | 6/8/2023 |
1.0.7 | 220 | 6/7/2023 |
1.0.6 | 168 | 6/6/2023 |
1.0.5 | 159 | 6/6/2023 |
1.0.4 | 167 | 6/5/2023 |
1.0.3 | 142 | 6/5/2023 |
1.0.2 | 165 | 6/5/2023 |