Koubot.Tool 1.0.5

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Koubot.Tool --version 1.0.5
                    
NuGet\Install-Package Koubot.Tool -Version 1.0.5
                    
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="Koubot.Tool" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Koubot.Tool" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="Koubot.Tool" />
                    
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 Koubot.Tool --version 1.0.5
                    
#r "nuget: Koubot.Tool, 1.0.5"
                    
#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 Koubot.Tool@1.0.5
                    
#: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=Koubot.Tool&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=Koubot.Tool&version=1.0.5
                    
Install as a Cake Tool

Koubot.Tool

A toolkit to assist in the development of Koubot related projects, providing a large number of extension methods, as well as some tool classes, can also be used to develop other projects (for lazy people lol), has also been uploaded to Nuget, you can use Nuget search Koubot to reference. The toolkit project does not have and will not have other project dependencies.

bases on .NET Standard 2.0

This is an incomplete version of the document, go to https://github.com/Euynac/Koubot.Plugin for more information

Some of the methods inside use features of VS plug-in ReSharper, and good hints and code checking are available when using ReSharper

  	//Ability to teach ReSharper null judgment (passed in null, returns true)		
  	[ContractAnnotation("null => true")] 
     public static bool IsNullOrEmpty([CanBeNull] this string s)
         => string.IsNullOrEmpty(s);
//https://www.jetbrains.com/help/resharper/Contract_Annotations.html#syntax

General

KouTaskDelayer

Timer that executes a task at particular time. if used it, it will takes a long-running thread to determine whether there is a task in the task list that needs to be executed. Supports same execution times.

KouTaskDelayer.AddTask(executeDate, new Task(() => { ... }));

SortTool

Extension methods in it can help to quickly complete the implementation of Comparison, Compare and other related methods, and it support chaining (to achieve weight sorting) and compare with null.

		public int CompareTo(SystemAliasList? other)
        {
            return this.CompareToObjAsc(IsGlobalAlias, other?.IsGlobalAlias, out int result)
                ?.CompareToObjAsc(IsGroupAlias, other?.IsGroupAlias, out result)
                ?.CompareToObjAsc(Advanced, other?.Advanced, out result)
                ?.CompareToObjAsc(AliasId, other?.AliasId, out result) == null ? result : 0;
        }

For example, to implement a CompareTo method for alias list, the effect is that the list will first sorted by the IsGlobalAlias field in ascending order, then by the IsGroupAlias field ascending, then by the Advanced field ascending , and finally by the AliasID field ascending, and the empty ones will be placed at the end (represent the null comparison support)

KouWatch

Unit test timer/efficiency comparator

When you need to time the execution time, you always need to write:

Stopwatch watch = new Stopwatch();
watch.Start();
...
watch.Stop();
Debug.WriteLine(watch.ElapsedMilliseconds);

Obviously very tedious, if you use KouWatch, you can use the following instead, and it will automatically output the time when the execution is finished.

			KouWatch.Start("testName", () =>
            {
                ...
            });

In addition, if you want to compare the execution time, there are methods for comparing, such as testing the efficiency of GetCustomAttributeCached compared to the system method.

			KouWatch.Start("cache", () =>
            {
                userBlacklist.FieldInfo(p => p.Reason);//二次封装GetCustomAttributeCached
            }, "default", () =>
            {
                property.GetCustomAttribute<KouAutoModelField>(); ;
            }, 100000);

Web

LeakyBucketRateLimiter

A leaky bucket algorithm flow limiter specifically for client-side API calls. The common implementation of the Leaky Bucket algorithm on the web does not calculate the time it takes for a request to reach the server, causing it easily to exceed the QPS specified by the server. This flow limiter implementation takes the request out of the bucket only after it is complete.

QPS support floating point number, such as 0.5, that is, 2 seconds before a call (in addition, if the QPS is very large, the interval call once will be at most 50ms , so the current maximum effective support for QPS for about 20 (later to optimize)) error in 0.5ms - 3ms or so

In addition, the flow limiter supports multiple APIs to limit the flow simultaneously and does not open new threads for automatic bucket leakage, but uses these threads to automatically control the requests in the bucket (but this also creates the disadvantage of poor support for large QPS)

support setting timeout time

Usage example:

using (var limiter = new LeakyBucketRateLimiter("test", TestQPS, TestLimitedSize))
{
    if (!limiter.CanRequest())
    {
        Console.WriteLine($"Request Failed: {limiter.ErrorMsg}");
        return;
    }
    Console.WriteLine($"An API request is sent");
}

The IDisposable feature is utilized so that when the request is out of the using range, the request is automatically considered finished and the request can be removed from the bucket

Encoder/Decoder

Currently provides base64 encryption and decryption (WebTool.EncodeBase64), and MD5 encryption (WebTool.EncryptStringMD5).

Random

RandomTool

Initialize only once and always use the same random number seed.

Those starting with XXX. are extension methods of the corresponding type

Method Description
IList.RandomGetOne Get a random item from IList and return default(T) if it fails
Array.RandomGetOne Get a random item from the Array and return default(T) if it fails
IList.RandomGetItems Randomly get a specified number of items (will not repeat), return list, failure returns null
IList.RandomList Disrupt the IList order and return it, or return the original list if it fails
IList.EnumRandomGetOne Randomly select one from Enum (need Enum class to be 0-n continuous)
IntervalDoublePair.GenerateRandomDouble Generate random double in an interval range (used with the IntervalDoublePair class in Tool)
GenerateRandomDouble Generate random double in an interval range
T.ProbablyDo There is an x% probability of not returning null, that is, there is an x% probability that it will do it (use ? on the chain truncation, for probabilistic execution)
T.ProbablyBe There is x% chance that the given object will be giving T
double.ProbablyTrue Returns true with x% probability
GetSecurityRandomByte Get a strong random byte array
GetRandomString Generate a random string
... ...

Math

ExpressionCalculator

Expression calculator that can be used to calculate expressions like sin(pi/2)^e-1*floor(3.5).

...

String

Format

Use

var result = $"{Reason?.Be($"\nReason:{Reason}")}";

instead of

var result = $"{(Reason == null ? null : $"\nReason:{Reason}" )}";

There are also obj.BeIfNotEmptyobj.BeIfNotWhiteSpaceobj.BeIfTrueobj.BeIfNotDefault

...

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.  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. 
.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.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Koubot.Tool:

Package Downloads
Koubot.SDK

SDK for building Koubot plugins or adapters.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.5-alpha 148 4/1/2024
2.0.3-alpha 303 6/20/2023
2.0.2-alpha 247 12/8/2022
2.0.1-alpha 293 6/29/2022
2.0.0-alpha 266 6/6/2022
1.0.5 595 3/28/2021
1.0.4 485 3/15/2021
1.0.3 471 2/9/2021
1.0.2 457 1/27/2021
1.0.1 608 8/14/2020
1.0.0 632 8/14/2020

v1.0.5 update
【document】 add english version document.
【format】BeNullOr is obsolete, use obj?.Be instead; add more methods like 'Be'
【KouTaskDelayer】 add Timer that executes a task at particular time.
【ExpressionCalculator】add ln、ceiling、floor support