MliybsToolKit 1.0.9

dotnet add package MliybsToolKit --version 1.0.9
                    
NuGet\Install-Package MliybsToolKit -Version 1.0.9
                    
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="MliybsToolKit" Version="1.0.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MliybsToolKit" Version="1.0.9" />
                    
Directory.Packages.props
<PackageReference Include="MliybsToolKit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MliybsToolKit --version 1.0.9
                    
#r "nuget: MliybsToolKit, 1.0.9"
                    
#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.
#:package MliybsToolKit@1.0.9
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MliybsToolKit&version=1.0.9
                    
Install as a Cake Addin
#tool nuget:?package=MliybsToolKit&version=1.0.9
                    
Install as a Cake Tool

MliybsToolKit

Mliybs的C#扩展工具包 写了一堆逆天类和逆天扩展方法

使用dotnet add package MliybsToolKit安装此包

扩展方法

整型(非负数)

GetEnumerator()

为整型扩展了GetEnumerator方法 有了该方法后整型就可以使用foreach进行遍历 具体作用相当于产生一个0到该整型的整数集合

示例代码:

using System;
using Mliybs.MliybsToolKit;

namespace Namespace
{
    class Program
    {
        public static void Main(string[] args)
        {
            foreach (var item in 5) Console.WriteLine(item);
        }
    }
}

输出结果:0 1 2 3 4 5

元组

GetEnumerator

为ValueTuple<int begin, int end>和ValueTuple<int begin, int end, int step>扩展了GetEnumerator方法 可以进行遍历 其中begin表示起始值 end表示结束值 step表示步长 指每隔几个值进行取值 不可为0 可为负

示例代码:

using System;
using Mliybs.MliybsToolKit;

namespace Namespace
{
    class Program
    {
        public static void Main(string[] args)
        {
            foreach (var item in (20, 5, -3)) Console.WriteLine(item);
        }
    }
}

输出结果:20 17 14 11 8 5

Count()和Get()

同上 Count()和Get()可以看做是上述集合的方法 用来获得该集合的元素数量和特定位置的元素

这个我觉得还有点用 比那个0到n都要靠专门方法来计算的强多了

MliybsIntObject和MliybsTupleObject

Count属性和this[]索引器

采用特殊的方法对Count和Get方法进行了封装(nmd不是单纯加壳子 很累的)

this[]索引器支持反向索引(如^0)和范围索引(如0..^0) 同常规Range不同 自定义类型在使用索引器时结尾索引的值会包含在集合中不会排除 需注意

ToString

现在使用MliybsIntObject和MliybsTupleObject的ToString方法会自动把其中的元素全部串联成一整个字符串了

IEnumerable

Print和PrintLine

简单来说就是所有集合都会实现的接口 (MliybsToolKit使用的整型和元组没有继承该接口 所以需要转换至自定义对象) 为该接口引用类型扩展了Print和PrintLine方法 可以将集合快速地用Console.Write和Console.WriteLine进行输出

(虽然是套壳子 但是我是不会道歉的)

LINQ兼容

上述数据类型在v1.0.6兼容了LINQ(v1.0.8修复BUG 建议使用v1.0.8以上版本) 由于数据转换受限 (想要兼容LINQ必须实现IEnumerable<T>接口或者实现到IEnumerable<T>的隐式或显式转换 前者受限于int和ValueTuple无法实现后者受限于扩展方法无法实现) 所以采用了自定义类MliybsIntObject和MliybsTupleObject

如果想要使用LINQ 必须使用显式转换 (但是定义的是隐式转换 方便后续版本开发) 或Transfer方法 之后才能使用LINQ

示例代码:

using System;
using System.Linq;
using Mliybs.MliybsToolKit;

namespace Namespace
{
    class Program
    {
        public static void Main(string[] args)
        {
            // 此处(MliybsIntObject)10外层的括号不可省略
            foreach (var item in ((MliybsIntObject)10).Where(i => i % 2 == 0)) Console.WriteLine(item);

            foreach (var item in (24, 1, -3).Transfer().Where(i => i % 2 == 0)) Console.WriteLine(item);
        }
    }
}

输出结果: 0 2 4 6 8 10 24 18 12 6

(v1.0.6我愿称之为史上最强 兼容了LINQ之后可操作能力指数级增长 这波薄纱了)

更新公告

v1.0.8

引入了更新公告(不然我自己都不知道自己写了什么)

加入了Print和PrintLine方法 加入了Count属性和索引器 修复了命名BUG 修复了元组索引值可以比最大值大一的BUG(忘了倒数第一是个数减一了 我是笨比) 修复了一系列BUG

v1.0.9

更新了Print和PrintLine方法 现在输出元素的时候前面会加上“元素类型:”了 覆写了ToString方法 修复了BUG

Product Compatible and additional computed target framework versions.
.NET 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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.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.0.9 352 5/1/2023
1.0.8 282 4/25/2023
1.0.7 269 4/25/2023
1.0.6 261 4/24/2023
1.0.5 294 4/5/2023
1.0.4 286 4/5/2023
1.0.3 281 4/5/2023
1.0.2 283 4/5/2023
1.0.1 293 4/5/2023
1.0.0 304 4/5/2023