Viyi.Util
2.0.1
See the version list below for details.
dotnet add package Viyi.Util --version 2.0.1
NuGet\Install-Package Viyi.Util -Version 2.0.1
<PackageReference Include="Viyi.Util" Version="2.0.1" />
paket add Viyi.Util --version 2.0.1
#r "nuget: Viyi.Util, 2.0.1"
// Install Viyi.Util as a Cake Addin
#addin nuget:?package=Viyi.Util&version=2.0.1
// Install Viyi.Util as a Cake Tool
#tool nuget:?package=Viyi.Util&version=2.0.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) 类型的问题;
- 参考 Kotlin,提供了
扩展 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 进行分析、确认并完成实现。
目标框架
-
支持:
- .NET
6.0/5.0
- .NET Core
3.1/3.0
- .NET
-
支持:
- .NET
6.0/5.0
- .NET Core
3.1/3.0/2.2/2.1/2.0
- .NET Framework
4.8/4.7.x/4.7/4.6.2
- .NET
文档
提供了 Xml Documentation (Viyi.Util.xml
) 随 NuGet 包发布。
没有制作专门供阅读的 API 文档,但是可以直接阅读源代码中的文档。
WIKI 中对部分功能进行了说明。
License
注:
Viyi.Util
v1.x
使用 MIT,从v2.0
开始变更为 MulanPSL2
Product | Versions 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. |
-
.NETStandard 2.0
- System.Threading.Tasks.Extensions (>= 4.5.4)
-
.NETStandard 2.1
- No dependencies.
-
net6.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 |
---|---|---|
2.1.2-beta | 137 | 4/17/2023 |
2.1.1 | 269 | 3/28/2023 |
2.1.0 | 309 | 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,878 | 8/25/2017 |
1.1.1 | 1,019 | 6/20/2017 |
1.1.0.1 | 997 | 6/9/2017 |
1.1.0 | 985 | 3/17/2017 |
1.0.4 | 1,374 | 9/15/2015 |
1.0.3 | 1,076 | 8/16/2015 |
1.0.2.3 | 1,072 | 7/9/2015 |
1.0.2 | 1,371 | 6/8/2015 |
1.0.0.1 | 1,447 | 11/29/2014 |