Sunnyyssh.ConsoleExtensions 1.1.0

dotnet add package Sunnyyssh.ConsoleExtensions --version 1.1.0                
NuGet\Install-Package Sunnyyssh.ConsoleExtensions -Version 1.1.0                
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="Sunnyyssh.ConsoleExtensions" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sunnyyssh.ConsoleExtensions --version 1.1.0                
#r "nuget: Sunnyyssh.ConsoleExtensions, 1.1.0"                
#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 Sunnyyssh.ConsoleExtensions as a Cake Addin
#addin nuget:?package=Sunnyyssh.ConsoleExtensions&version=1.1.0

// Install Sunnyyssh.ConsoleExtensions as a Cake Tool
#tool nuget:?package=Sunnyyssh.ConsoleExtensions&version=1.1.0                

Sunnyyssh.ConsoleExtensions

Defined types description

ConsoleUI

public static class ConsoleUI
Defined static methods
Method signature Description
LoopMethodTillBreak(Action?, ConsoleKey, bool, string?) Loops given method invoking untill user breaks it using specified key.
SetConsoleFileInput(string) Opens file and reads from it instead of console standard stream. (When Console.ReadLine() invoked text from file will be read).
SetConsoleStringInput(string stringInput) Opens string stream and reads from it instead of standard console stream. (When Console.ReadLine() invoked text from string will be read).
SetConsoleStansardInput() Sets back standard input.
PrintMany(params object[]) Writes objects to console with space separator.
PrintMany(char, params object[]) Writes objects to console with given separator
PrintMany(string, params object[]) Writes objects to console with given separator

Here is an example of their usage.

// It will invoke OneFrame() then write to console message to press something then invokes again if continue. Just try it.
ConsoleUI.LoopMethodTillBreak(OneFrame, ConsoleKey.Escape, true);

void OneFrame()
{
    Console.WriteLine("Hi, thanks for using my package <3");
}
// Sets console input stream from file
ConsoleUI.SetConsoleFileInput(@"im _too_lazy.txt");
// It will read from file, not from console. It's actually useful when you debug something many times with same input. Just write it to the file and make this.
string? s = Console.ReadLine();

Console.WriteLine(s);
// The string which has input like you write it to console yourself
string stringInput = "Hey there! \n " +
           "You can follow tg channel @vowtostrive \n" +
           "1 2 3 4";
// Sets input of console from string
ConsoleUI.SetConsoleStringInput(stringInput);
// Below just simple reading "from console" but actually from string
string? greeting = Console.ReadLine(); // "Hey there! "
string? tgChannel = Console.ReadLine(); // "You can follow tg channel @vowtostrive "
int[] numbers = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); // int[4] {1, 2, 3, 4}
string s = "line from string";
ConsoleUI.SetConsoleStringInput(s);
string stringFromString = Console.ReadLine();
//Sets back console standard stream input
ConsoleUI.SetConsoleStandardInput();
// This string will be read from console
string stringFromConsole = Console.ReadLine();
ConsoleUI.PrintMany(new Guid(), DateTime.Now.ToString("d"), "Haha"); 
// 00000000-0000-0000-0000-000000000000 11.11.2023 Haha
ConsoleUI.PrintMany(separator:'\t', 2, 3, 23); 
// 2       3       23
ConsoleUI.PrintMany(" and ", "Pinokio", "Shrek", "Smurf"); 
// Pinokio and Shrek and Smurf

ConsoleObjectsExtensions

public static class ConsoleObjectsExtensions
Defined static extension methods
Method signature Description
Print(this bool) Writes bool value to console.
Print(this object?) Writes any object value to console, "null" if it is null.
Print(this int) Writes int value to console.
Print(this double) Writes double value to console.
Print(this IFormattable?, string?) Writes IFormattable value with given format to console.
Print(this int, string?) Writes int value with given format to console.
Print(this double, string?) Writes double value with given format to console.
Print<T>(this IEnumerable<T>?) Writes IEnumerable<T> to console with space separator.
Print<T>(this IEnumerable<T>?, char) Writes IEnumerable<T> to console with given separator.
Print<T>(this IEnumerable<T>?, string?) Writes IEnumerable<T> to console with given separator.
Print<TFormattable>(this IEnumerable<TFormattable>?, char, string?) Writes IEnumerable<T> to console with given separator and format.
Print<TFormattable>(this IEnumerable<TFormattable>?, string?, string?) Writes IEnumerable<T> to console with given separator and format.
Print<T>(this IEnumerable<T>?, char, Func<T, string>) Writes IEnumerable<T> to console with given separator and convertor.
Print<T>(this IEnumerable<T>?, string?, Func<T, string>) Writes IEnumerable<T> to console with given separator and convertor.

Here is an example of their usage


bool isItImpossible = false;
isItImpossible.Print(); 
// False

object o = new Guid(1, 2, 3, 4, 5, 6 ,7, 8, 9, 10, 11);
o.Print();
// 00000001-0002-0003-0405-060708090a0b

int dotnetLoveRate = Int32.MaxValue;
dotnetLoveRate.Print();
// 2147483647

Math.PI.Print();
// 3,141592653589793

DateTime.Now.Print(format: "d");
// 11.11.2023

12233424.Print("E");
// 1,223342E+007

Math.Pow(Math.PI, 2).Print("f2");
// 9,869604401089358

Range[] ranges = new Range[] { 1..2, 3..4, Range.All };
ranges.Print();
// 1..2 3..4 0..^0

Enumerable.Range(-10, 27).Where(x => x % 7 == 0).Print('\t');
// -7      0       7       14

"Paris, Moscow, Kazan, ".Split(", ", StringSplitOptions.RemoveEmptyEntries).Print(";\n");
// Paris;
// Moscow;
// Kazan

double[] whatIsIt = { 1.0 / 3, 1.0 / 999, 1.0 / 12 };
whatIsIt.Print(' ', "f4");
// 0,3333 0,0010 0,0833

Enumerable.Range(8, 16).Print("; ", "X");
// 8; 9; A; B; C; D; E; F; 10; 11; 12; 13; 14; 15; 16; 17

new int[3] {1, 2, 14}.Print(' ', x => $"oil_{x}");
// oil_1 oil_2 oil_14

whatIsIt.Print(" and ", d => $"{d * 2:P} loaded");
// 66,67 % loaded and 0,20 % loaded and 16,67 % loaded

Thanks for installing my package <3 You can write me to my telegram @sunnyyssh

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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
1.1.0 219 11/11/2023
1.0.0 135 11/10/2023

Added documentation. Read it in README file