Tools.Generic
1.0.0
dotnet add package Tools.Generic --version 1.0.0
NuGet\Install-Package Tools.Generic -Version 1.0.0
<PackageReference Include="Tools.Generic" Version="1.0.0" />
<PackageVersion Include="Tools.Generic" Version="1.0.0" />
<PackageReference Include="Tools.Generic" />
paket add Tools.Generic --version 1.0.0
#r "nuget: Tools.Generic, 1.0.0"
#:package Tools.Generic@1.0.0
#addin nuget:?package=Tools.Generic&version=1.0.0
#tool nuget:?package=Tools.Generic&version=1.0.0
Table of Content
- Extensions
- Logging
- void <T>.Log(T value)
- void <T>.Log(T value, string prependText)
- void <T>.Log(T value, string prependText, string appendText)
- void <T>.LogAsJson(T value)
- void <T>.LogAsJson(T value, string prependText)
- void <T>.LogAsJson(T value, string prependText, string appendText)
- void <T>.LogAsXml(T value)
- void <T>.LogAsXml(T value, string prependText)
- void <T>.LogAsXml(T value, string prependText, string appendText)
- Console
- void ConsoleColor.Write(object value)
- void ConsoleColor.WriteLine(object value)
- Data conversion
- string Stream.AsString()
- string string.Collapse()
- string <T>.AsJson()
- string <T>.AsXml()
- string byte[].AsString()
- string byte[].AsString(Encoding encoding)
- byte[] string.AsByteArray()
- byte[] string.AsByteArray(Encoding encoding)
- Compression
- byte[] byte[].GZipCompress(CompressionLevel level)
- byte[] byte[].GZipDecompress()
- byte[] byte[].BrotliCompress(CompressionLevel level)
- byte[] byte[].BrotliDecompress()
- Logging
Tools.Generic.Logging
Action<object> LoggingAction(object data)
The method used when Log methods are called. This is defaulted to Console.WriteLine
LoggingExtensions.LoggingAction = (object data) =>
{
Console.WriteLine(data);
}
<void> <T>.Log(T value)
Performs a .ToString() on value and calls the logging action.
int number = 3;
number.Log(); // 3
<void> <T>.Log(T value, string prependText)
Performs a .ToString() on value, prepends text then calls the logging action.
int number = 3;
number.Log("Number: "); // Number: 3
<void> <T>.Log(T value, string prependText, string appendText)
Performs a .ToString() on value, prepends and appends text then calls the logging action.
int number = 3;
number.Log("There are ", " items left"); // There are 3 items left
<void> <T>.LogAsJson(T value)
Performs a Json.Serialize on value and calls the logging action.
int number = 3;
number.Log(); // 3
<void> <T>.LogAsJson(T value, string prependText)
Performs a Json.Serialize on value, prepends text then calls the logging action.
int number = 3;
number.Log("Number: "); // Number: 3
<void> <T>.LogAsJson(T value, string prependText, string appendText)
Performs a Json.Serialize on value, prepends and appends text then calls the logging action.
int number = 3;
number.Log("There are ", " items left"); // There are 3 items left
<void> <T>.LogAsXml(T value)
Converts value to a XML sheet then calls the logging action.
int number = 3;
number.Log(); // 3
<void> <T>.LogAsXml(T value, string prependText)
Converts value to a XML sheet, prepends text then calls the logging action.
int number = 3;
number.Log("Number: "); // Number: 3
<void> <T>.LogAsXml(T value, string prependText, string appendText)
Converts value to a XML sheet, prepends and appends text then calls the logging action.
int number = 3;
number.Log("There are ", " items left"); // There are 3 items left
Tools.Generic.Console
Webkit has a couple extensions to make console logging with color quicker and easier.
<void> ConsoleColor.WriteLine(object value)
Writes value and appends Environment.NewLine to the console with specified console color.
ConsoleColor.Yellow.WriteLine("[Warning] Service is disabled, this may impact user experience."); // [Warning] Service is disabled, this may impact user experience.\r\n
<void> ConsoleColor.Write(object value)
Writes value to the console with specified console color.
ConsoleColor.Yellow.Write("[Warning] Service is disabled, this may impact user experience."); // [Warning] Service is disabled, this may impact user experience.
Tools.Generic.DataConversion
These extensions help convert and manage data to different formats.
<string> Stream.AsString()
Converts a stream to a string.
<string> string.Collapse()
Collapses the newlines in the string, making it one line.
@"Lorem ipsum
dolor sit
amet".Collapse();
// Lorem ipsum dolor sit amet
<string> <T>.AsJson()
Converts any value to a json string
User user = new User()
{
Name = "John",
Email = "john@example.com"
};
user.AsJson();
/*
{
"Name": "John",
"Email": "john@example.com"
}
*/
<string> <T>.AsXml()
Converts any value to a XML sheet
User user = new User()
{
Name = "John",
Email = "john@example.com"
};
user.AsXml();
/*
<User xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Name>John</Name>
<Email>john@example.com</Email>
</User>
*/
Tools.Generic.Compression
These extensions help with compressing and decompressing byte arrays.
<byte[]> byte[].GZipCompress(CompressionLevel level)
Compresses a byte array using GZip compression with specified compression level.
byte[] data = Encoding.UTF8.GetBytes("Hello, World!");
byte[] compressedData = data.GZipCompress(CompressionLevel.Optimal);
<byte[]> byte[].GZipDecompress()
Decompresses a GZip compressed byte array.
byte[] decompressedData = compressedData.GZipDecompress();
string result = Encoding.UTF8.GetString(decompressedData); // "Hello, World!"
<byte[]> byte[].BrotliCompress(CompressionLevel level)
Compresses a byte array using Brotli compression with specified compression level.
byte[] data = Encoding.UTF8.GetBytes("Hello, World!");
byte[] compressedData = data.BrotliCompress(CompressionLevel.Optimal);
<byte[]> byte[].BrotliDecompress()
Decompresses a Brotli compressed byte array.
byte[] decompressedData = compressedData.BrotliDecompress();
string result = Encoding.UTF8.GetString(decompressedData); // "Hello, World!"
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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. |
-
net9.0
- System.Runtime.Caching (>= 9.0.10)
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.0 | 227 | 10/23/2025 |
Initial release