JiuLing.CommonLibs 1.1.33

There is a newer version of this package available.
See the version list below for details.
dotnet add package JiuLing.CommonLibs --version 1.1.33
NuGet\Install-Package JiuLing.CommonLibs -Version 1.1.33
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="JiuLing.CommonLibs" Version="1.1.33" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JiuLing.CommonLibs --version 1.1.33
#r "nuget: JiuLing.CommonLibs, 1.1.33"
#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 JiuLing.CommonLibs as a Cake Addin
#addin nuget:?package=JiuLing.CommonLibs&version=1.1.33

// Install JiuLing.CommonLibs as a Cake Tool
#tool nuget:?package=JiuLing.CommonLibs&version=1.1.33

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

一个基于.NET Standard 2.0的通用类库

一个.NET Standard 2.0下整理的通用类库,基于MIT License

目前包含的功能有:Dictionary对象对比工具、枚举描述、字符串扩展、日志、通用模型、Cookie工具、网络请求工具、操作系统版本帮助类、随机数、MD5SHA1、正则表达式、时间戳、线程帮助类、Guid帮助类、程序版本帮助类、命令行参数解析工具。

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();
    
  • ListExtendTools类:List的一些扩展方法

    ListDataTable

    var a=new List<T>();
    a.ToDataTable();
    
  • 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
    {
        public int Code { get; set; }
        public string Message { get; set; }
    }
    
    public class JsonResult<T>
    {
        public int Code { get; set; }
        public string Message { get; set; }
        public T Data { get; set; }
    }
    
  • AppUpgradeInfo类:通用的App自动更新所需的模型

    public class AppUpgradeInfo
    {
        /// <summary>
        /// 程序名称
        /// </summary>
        public string Name { get; set; }        
        /// <summary>
        /// 当前版本
        /// </summary>
        public string Version { get; set; }
        /// <summary>
        /// 程序运行的最小版本
        /// </summary>
        public string MinVersion { get; set; }
        /// <summary>
        /// 下载地址
        /// </summary>
        public string DownloadUrl { get; set; }
        /// <summary>
        /// 更新日志
        /// </summary>
        public string Log { get; set; }
        /// <summary>
        /// 时间
        /// </summary>
        public DateTime CreateTime { 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);
    
    //异步发送一个GET请求,返回一个文件的字节数组
    public async Task<byte[]> GetFileByteArray(string url, IProgress<float> progress = null, int bufferSize = 8192)
    
    //异步发送一个表单形式的Post请求,返回一个字符串
    public async Task<string> PostFormReadString(string url, IEnumerable<KeyValuePair<string, string>> data);
    
    //异步发送一个字符串形式的Post请求,返回一个字符串
    public async Task<string> PostStringReadString(string url, string data);
    
    //异步发送一个Json形式的Post请求(使用UTF8编码),返回一个字符串
    public async Task<string> PostJsonReadString(string url, string data);
    
    //异步发送一个表单形式的Post请求,返回一个字节数组
    public async Task<byte[]> PostFormReadByteArray(string url, IEnumerable<KeyValuePair<string, string>> data)
    

OS命名空间

该命名空间下是一些操作系统相关的类

  • VersionUtils类:操作系统版本帮助类

    VersionUtils.IsWindows7;     //当前系统是否为Win7
    VersionUtils.IsWindows8;     //当前系统是否为Win8
    VersionUtils.IsWindows81;    //当前系统是否为Win8.1
    VersionUtils.IsWindows10;    //当前系统是否为Win10   
    
    //获取当前操作系统的版本,返回值为一个OSVersionEnum枚举值
    VersionUtils.GetOSVersion();
    
    public enum OSVersionEnum
    {
        [Description("Windows7")]
        Windows7,
        [Description("Windows8")]
        Windows8,
        [Description("Windows8.1")]
        Windows81,
        [Description("Windows10")]
        Windows10,
        [Description("未知")]
        Unknown,
    }
    

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);
    

Security命名空间

该命名空间下是一些安全相关的类

  • MD5Utils类:MD5帮助类

    //默认编码格式
    public static Encoding DefaultEncoding = Encoding.UTF8;
    
    //计算字符串的32位MD5值(小写)
    MD5Utils.GetLowerValue();
    //计算字符串的32位MD5值(大写)
    MD5Utils.GetUpperValue();
    
  • SHA1Utils类:SHA1的帮助类

    //计算文件的SHA1值(小写)
    SHA1Utils.GetFileLowerValue();
    //计算文件的SHA1值(大写)
    SHA1Utils.GetFileUpperValue();
    

Text命名空间

该命名空间下是一些文本处理的类

  • RegexUtils类:正则表达式相关的类

    //文本是否与正则表达式匹配
    RegexUtils.IsMatch(111,@"\d{3}");
    
    //根据正则表达式替换;该示例返回:<xxx>
    RegexUtils.Replace("<test>",@"test","xxx");
    
    //返回正则表达式的第一个匹配项;返回test12
    RegexUtils.GetFirst("test123test456", @"test\d{2}");
    
    //返回正则表达式匹配到的所有项
    RegexUtils.GetAll(input, pattern);
    
    //按照正则表达式分组名称返回第一个匹配项;a="jiuling"
    string a=GetOneGroupInFirstMatchTest("name:jiuling;age:0;",@"name:(?<name>\w*);");
    
    //按照正则表达式分组名称返回所有匹配项;如果没有匹配到任何项,success=false,否则result返回一个IDictionary对象,其Key值为Group的名称 
    (bool success, IDictionary<string, string> result)=RegexUtils.GetMultiGroupInFirstMatch("name:jiuling;age:0;",@"name:(?<name>\w*);age:(?<age>\w*);");
    //返回值 success=true,result["name"]="jiuling",result["age"]="0"
    
  • StartupCommandUtils类:启动参数解析工具类

    检查是否包含参数

    StartupCommandUtils.Initialize("-a test1 test2 -b");    
    bool result = StartupCommandUtils.HasCommand("-a");
    //result的值为True
    

    获取指定参数

    StartupCommandUtils.Initialize("-a test1 test2 -b -c test-c");
    IList<string> result = StartupCommandUtils.GetCommandValue("-a");
    //result包含"test1"和"test3"两个值
    

    尝试获取指定参数

    StartupCommandUtils.Initialize("-a test1 -b test");    
    bool result = StartupCommandUtils.TryGetCommandValue("-a", out args);
    //result为是否找到对应参数,args为获取到的参数值
    
  • 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);
    

根命名空间

  • GuidUtils类:Guid帮助类

    //获取一个Guid,格式:9af7f46a-ea52-4aa3-b8c3-9fd484c2af12
    GuidUtils.GetFormatDefault();
    
    //获取一个Guid,格式:e0a953c3ee6040eaa9fae2b667060e09
    GuidUtils.GetFormatN();
    
    //获取一个Guid,格式:9af7f46a-ea52-4aa3-b8c3-9fd484c2af12
    GuidUtils.GetFormatD();
    
    //获取一个Guid,格式:{734fd453-a4f8-4c5d-9c98-3fe2d7079760}
    GuidUtils.GetFormatB();
    
    //获取一个Guid,格式:(ade24d16-db0f-40af-8794-1e08e2040df3)
    GuidUtils.GetFormatP();
    
    //获取一个Guid,格式:{0x3fa412e3,0x8356,0x428f,{0xaa,0x34,0xb7,0x40,0xda,0xaf,0x45,0x6f}}
    GuidUtils.GetFormatX();
    
  • VersionUtils类:程序版本帮助类

    //检查当前版本是否需要更新
    bool CheckNeedUpdate(Version currentVersion, Version newVersion);
    
    //检查当前版本是否需要更新
    bool CheckNeedUpdate(string currentVersion, string newVersion);
    
    //检查当前版本是否需要更新。返回(是否需要自动更新,当前版本是否允许使用)
    (bool IsNeedUpdate, bool IsAllowUse) CheckNeedUpdate(Version currentVersion, Version newVersion, Version minVersion)
    
    //检查当前版本是否需要更新。返回(是否需要自动更新,当前版本是否允许使用)
    (bool IsNeedUpdate, bool IsAllowUse) CheckNeedUpdate(string currentVersion, string newVersion, string minVersion)
    

3️⃣ License

本项目基于MIT License

Product 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 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 Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 128 2/5/2024
1.6.6 259 9/13/2023
1.6.5 120 9/13/2023
1.6.3 139 9/12/2023
1.6.2 129 9/10/2023
1.6.1 122 9/9/2023
1.6.0 122 9/2/2023
1.5.8 222 7/19/2023
1.5.7 184 4/13/2023
1.5.6 286 3/18/2023
1.5.5 223 3/9/2023
1.5.4 249 2/21/2023
1.5.2 370 11/16/2022
1.5.1 477 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