JiuLing.CommonLibs
1.0.1
See the version list below for details.
dotnet add package JiuLing.CommonLibs --version 1.0.1
NuGet\Install-Package JiuLing.CommonLibs -Version 1.0.1
<PackageReference Include="JiuLing.CommonLibs" Version="1.0.1" />
paket add JiuLing.CommonLibs --version 1.0.1
#r "nuget: JiuLing.CommonLibs, 1.0.1"
// Install JiuLing.CommonLibs as a Cake Addin
#addin nuget:?package=JiuLing.CommonLibs&version=1.0.1
// Install JiuLing.CommonLibs as a Cake Tool
#tool nuget:?package=JiuLing.CommonLibs&version=1.0.1
一个基于.NET 5
的通用类库
一个.NET 5
下整理的通用类库。
1️⃣ 项目初衷
新建项目后,经常发现连个string.IsEmpty()
都没有、想要个Json
的通用返回值吧,也没有:disappointed_relieved::disappointed_relieved:,当然,还有等等等等等等等等。。。所以我决定整理并集成一下自己平时用的比较多的一些工具类,然后发布到NuGet
,以后走哪用哪啊有木有~~
2️⃣ 使用说明
- 类库中以
Utils
结尾的类,都提供了静态方法,可以直接调用- 类库中的命名空间和类名,尽量与
.NET
保持一致
Collections
命名空间
该命名空间下是一些集合相关的类
DictionaryComparer
类:Dictionary
对象对比工具var x = new Dictionary<string, string>(); x.Add("a1", "b1"); var y = new Dictionary<string, string>(); y.Add("a1", "b1"); Assert.IsTrue(_myComparer.Equals(x, y));
ExtensionMethods
命名空间
该命名空间下是一些通用的扩展方法
EnumExtension
类:枚举类型的扩展方法public enum MyEnum { [Description("一")] One, [Description("二")] Two, Three } //获取枚举的描述信息,下面的例子将返回“一” MyEnum.One.GetDescription(); //如果枚举字段没有设置Description特性,将返回自身的ToString()形式,下面的例子将返回“Three” MyEnum.Three.GetDescription();
StringExtension
类:字符串类型的扩展方法"abc".IsEmpty(); //字符串是否为空 "abc".IsNotEmpty(); //字符串是否不为空 "https://jiuling.me".ToUri(); //将字符串转为Uri对象
Log
命名空间
该命名空间下是一些通用的日志帮助类
ILogger
接口:负责简单的日志的写入ILogger logger = LogManager.GetLogger(); // logger.SetLogDirectory("C:\\") //设置日志文件的路径,默认为“程序集路径\log” // .SetFileNameFormat("yyyyMMdd") //设置日志文件名的格式,默认为“yyyy-MM-dd” // .SetFileExpandedName(".txt"); //设置日志文件的扩展名,默认为“.log” logger.Write("test");
Model
命名空间
该命名空间下是一些通用的数据模型
JsonResult
类:一个通用的Json
返回值模型public class JsonResult<T> { public int Code { get; set; } public string Message { get; set; } public T Data { get; set; } }
Net
命名空间
该命名空间下是网络相关的类
CookieUtils
类:Cookie
相关的工具//将CookieContainer转换为指定格式的字符串形式,方便本地储存 public static string CookieContainerToString(CookieContainer cookieContainer); //将指定格式的字符串转换为CookieContainer public static CookieContainer StringToCookieContainer(string cookies);
HttpClientHelper
类:网络请求类工具,使用HttpClient
实现//异步发送一个GET请求,返回一个字符串 public async Task<string> GetReadString(string url); //异步发送一个GET请求,返回一个字节数组 public async Task<byte[]> GetReadByteArray(string url); //异步发送一个表单形式的Post请求,返回一个字符串 public async Task<string> PostFormReadString(string url, IEnumerable<KeyValuePair<string, string>> data); //异步发送一个表单形式的Post请求,返回一个字节数组 public async Task<byte[]> PostFormReadByteArray(string url, IEnumerable<KeyValuePair<string, string>> data)
Random
命名空间
该命名空间下是一些随机数相关的类
RandomUtils
类:随机数帮助类RandomUtils.GetOneByLength(); //返回一个长度为10的随机数 RandomUtils.GetOneByLength(20); //返回一个长度为20的随机数 //方法定义 T GetOneFromList<T>(IList<T> input) //随机返回list中的一个元素 var list = new List<string>(); list.Add("a"); list.Add("b"); RandomUtils.GetOneFromList<string>(list);
Text
命名空间
该命名空间下是一些文本处理的类
RegexUtils
类:正则表达式相关的类//文本是否与正则表达式匹配 RegexUtils.IsMatch(111,@"\d{3}"); //返回正则表达式的第一个匹配项;返回test12 RegexUtils.GetFirst("test123test456", @"test\d{2}"); //返回正则表达式匹配到的所有项 RegexUtils.GetAll(input, pattern); //按照正则表达式分组名称返回第一个匹配项;a="jiuling" string a=GetOneGroupInFirstMatchTest("name:jiuling;age:0;",@"name:(?<name>\w*);"); //按照正则表达式分组名称返回所有匹配项;obj.name="jiuling" obj.age="0" dynamic obj=RegexUtils.GetMultiGroupInFirstMatch("name:jiuling;age:0;",@"name:(?<name>\w*);age:(?<age>\w*);");
TimestampUtils
类:时间戳相关的类//获取一个10位的时间戳 TimestampUtils.GetLen10(); //获取一个13位的时间戳 TimestampUtils.GetLen13(); //将时间转换为一个10位的时间戳 1626961721 TimestampUtils.ConvertToLen10("2021-07-22 21:48:41"); //将时间转换为一个13位的时间戳 1626961721000 TimestampUtils.ConvertToLen13("2021-07-22 21:48:41"); //将10位或13位的时间戳转换为一个DateTime对象(该方法会自动判断长度) 2021-07-22 21:48:41 TimestampUtils.ConvertToDateTime(1626961721000)
Threading
命名空间
该命名空间下是一些线程相关的类
ThreadUtils
类:线程帮助类//随机将线程挂起1-10秒 ThreadUtils.SleepRandomSecond(1,10); //随机将线程挂起1-10毫秒 ThreadUtils.SleepRandomMillisecond(2000, 5000);
3️⃣ License
本项目基于MIT License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. 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 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. |
-
net5.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.6.7 | 137 | 2/5/2024 |
1.6.6 | 261 | 9/13/2023 |
1.6.5 | 122 | 9/13/2023 |
1.6.3 | 141 | 9/12/2023 |
1.6.2 | 133 | 9/10/2023 |
1.6.1 | 124 | 9/9/2023 |
1.6.0 | 124 | 9/2/2023 |
1.5.8 | 228 | 7/19/2023 |
1.5.7 | 186 | 4/13/2023 |
1.5.6 | 288 | 3/18/2023 |
1.5.5 | 225 | 3/9/2023 |
1.5.4 | 251 | 2/21/2023 |
1.5.2 | 370 | 11/16/2022 |
1.5.1 | 479 | 11/9/2022 |
1.4.2 | 341 | 11/1/2022 |
1.3.9 | 368 | 10/23/2022 |
1.3.7 | 389 | 10/2/2022 |
1.3.6 | 396 | 9/13/2022 |
1.3.5 | 410 | 8/19/2022 |
1.3.4 | 359 | 8/19/2022 |
1.3.3 | 413 | 8/3/2022 |
1.3.2 | 426 | 7/27/2022 |
1.3.1 | 415 | 7/27/2022 |
1.3.0 | 414 | 7/27/2022 |
1.2.8 | 422 | 7/19/2022 |
1.2.7 | 432 | 7/13/2022 |
1.2.6 | 411 | 6/13/2022 |
1.2.5 | 465 | 4/12/2022 |
1.2.4 | 439 | 4/5/2022 |
1.2.3 | 530 | 2/23/2022 |
1.2.2 | 466 | 2/21/2022 |
1.2.1 | 449 | 2/14/2022 |
1.2.0 | 450 | 2/14/2022 |
1.1.33 | 444 | 2/14/2022 |
1.1.32 | 439 | 2/14/2022 |
1.1.31 | 466 | 2/14/2022 |
1.1.30 | 485 | 2/9/2022 |
1.1.29 | 499 | 1/26/2022 |
1.1.28 | 477 | 1/26/2022 |
1.1.27 | 468 | 1/26/2022 |
1.1.26 | 465 | 1/26/2022 |
1.1.25 | 436 | 1/25/2022 |
1.1.24 | 434 | 1/25/2022 |
1.1.23 | 475 | 1/25/2022 |
1.1.22 | 484 | 1/25/2022 |
1.1.21 | 460 | 1/25/2022 |
1.1.20 | 467 | 1/25/2022 |
1.1.19 | 463 | 1/25/2022 |
1.1.18 | 463 | 1/20/2022 |
1.1.17 | 463 | 1/19/2022 |
1.1.16 | 471 | 1/19/2022 |
1.1.15 | 448 | 1/17/2022 |
1.1.14 | 463 | 1/17/2022 |
1.1.13 | 467 | 1/14/2022 |
1.1.12 | 330 | 11/23/2021 |
1.1.11 | 324 | 11/23/2021 |
1.1.10 | 739 | 11/21/2021 |
1.1.9 | 705 | 11/21/2021 |
1.1.8 | 1,363 | 11/20/2021 |
1.1.7 | 333 | 11/15/2021 |
1.1.6 | 323 | 11/5/2021 |
1.1.5 | 381 | 11/4/2021 |
1.1.4 | 390 | 11/3/2021 |
1.1.3 | 404 | 10/18/2021 |
1.1.2 | 406 | 9/18/2021 |
1.1.1 | 380 | 9/18/2021 |
1.1.0 | 370 | 9/17/2021 |
1.0.1 | 391 | 8/22/2021 |
1.0.0 | 353 | 8/12/2021 |