Viyi.Util 2.1.1

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

// Install Viyi.Util as a Cake Tool
#tool nuget:?package=Viyi.Util&version=2.1.1

Viyi.Util - .NET 的常用工具扩展

Viyi.Util v2 对该工具库进行了完全重写,完全兼容 v1。

v2 参考其它现代高级语言、类库和日常使用的情况,提供一些常见的工具函数和工具类,以 C# 的“扩展函数”作为主要实现形式,也包含一些 Helper 静态类和其他工具类。

其他相关类库

Viyi.Util 包含内容较多,依赖项也较多,部分功能已经分离出去,按功能分解成一些小工具库

  • Viyi.Strings 专注于扩展字符串相关的功能和工具函数
  • Viyi.Bytes (coming soon) 专注于扩展二进制相关的功能和工具函数

获取

Viyi.Util 通过 NuGet 发布。

Visual Studio 包管理器控制台 中运行下面的命令获取:

PM> Install-Package Viyi.Util

或者在 管理 NuGet 程序包对话框 中安装。

主要特性 (Features)

  • 扩展 object

    • 参考 Kotlin,提供了 .Also().Let() 扩展,同时支持它们的异步版本;
    • 提供 ToXxxx()ConvertTo() 方法,是 System.Convert 类中相关功能的去异常封装;
    • 提供 As() 方法弥补 as 关键字不能应用于结构体 (struct) 类型的问题;
  • 扩展 Linq (Enumerable),

    • 提供 ForEach() / ForEachAsync 扩展;

      注:Viyi.Util 目前不支持 IAsyncEnumerable,请使用 System.Linq.Async

    • 提供 AsToArray()AsToList() 先尝试 as 操作,最大避免重新生成数组或列表对象;

    • 为 .NET6 以下框架提供 MaxBy()MinBy()

    • List<T>T[] 分别提供 Shuffle() 扩展用来打乱其内部元素的顺序;

    • ViyiEnumerable<T>.Of(params T[]) 从一组单个对象创建 IEnumerable<T>

  • 扩展 boolean

    • it.Then()if / if ... else ... 的表达式形式;
    • it.Else()if not 的表达式形式;
    • it.Then(fnThen, fnElse)? : 的函数调用形式;
  • ViyiRandom 提供随机数工具

    • ViyiRandom.Create() 创建随机数据发生器 (Random)

      在 netstandard2.1 和 net6 中使用 Random.Shared 来产生随机种子,在 netstandard2.0 中使用类似的方式,通过一个静态且线程安全的 Random 对象来产生随机种子。

    • ViyiRandom.RandomIndexes() 产生一组以 0 开始的随机序数,可用于产生顺序随机的数据

  • EnumHelper 为枚举类型提供工具方法

    • EnumHelper.EnumerateWith() 将枚举中定义的枚举值转换为指定对象的 IEnumerable
    • EnumHelper.GetDescription() 获取枚举值的 DescriptionAttribute 描述信息;
    • EnumHelper.EnumerateWithDescription()EnumerateWith()类似,但会去分析 DescriptionAttribute 属性,结果保存在 EnumEntry 对象中;
    • EnumHelper.Enumerate() 得到 IEnumerable<KeyValuePair>
    • EnumHelper.ToNameValueCollection() 得到 NameValueCollection(可通过参数交换 Key-Value)
  • 对 Compare 和 Equiality 的支持

    • LambdaCompare 可以通过 Lambda 来产生 IComparer<T> 对象,避免定义类;
    • LambdaEqualityComparer 通过 Lambda 产生 IEqualityComparer<T> 对象,避免定义类;
  • 其它工具

    会根据 Issue 进行分析、确认并完成实现。

目标框架

文档

提供了 Xml Documentation (Viyi.Util.xml) 随 NuGet 包发布。

没有制作专门供阅读的 API 文档,但是可以直接阅读源代码中的文档。

WIKI 中对部分功能进行了说明。

License

木兰宽松许可证,第2版 (MulanPSL2)

注:

Viyi.Util v1.x 使用 MIT,从 v2.0 开始变更为 MulanPSL2

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  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 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 is compatible. 
.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
2.1.2-beta 135 4/17/2023
2.1.1 267 3/28/2023
2.1.0 306 12/22/2022
2.0.1 411 9/30/2022
2.0.1-beta 147 9/11/2022
2.0.0-preview-1 164 7/10/2022
1.1.2 1,876 8/25/2017
1.1.1 1,017 6/20/2017
1.1.0.1 995 6/9/2017
1.1.0 983 3/17/2017
1.0.4 1,372 9/15/2015
1.0.3 1,075 8/16/2015
1.0.2.3 1,070 7/9/2015
1.0.2 1,369 6/8/2015
1.0.0.1 1,445 11/29/2014