IOUtils 1.7.0

dotnet add package IOUtils --version 1.7.0
                    
NuGet\Install-Package IOUtils -Version 1.7.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="IOUtils" Version="1.7.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IOUtils" Version="1.7.0" />
                    
Directory.Packages.props
<PackageReference Include="IOUtils" />
                    
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 IOUtils --version 1.7.0
                    
#r "nuget: IOUtils, 1.7.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.
#:package IOUtils@1.7.0
                    
#: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=IOUtils&version=1.7.0
                    
Install as a Cake Addin
#tool nuget:?package=IOUtils&version=1.7.0
                    
Install as a Cake Tool

IOUtils: Input and Output Utility Package for .NET

Build, Test and Publish

Installation

Install the IOUtils NuGet package using the .NET CLI:

dotnet add package IOUtils

Features

Input retrieval

Retrieve text from the user

TextInput is a class that allows for the retrieval of text from the user.

using IOUtils.Input;

string text = TextInput.GetText("Enter some text");
string nonEmptyText = TextInput.GetNonEmptyText("Enter some (non-empty) text");
Retrieve number from the user

NumberInput is a generic class that allows for the retrieval of a number from the user. Optionally, a minimum and maximum value can be specified to restrict the input range.

using IOUtils.Input;

int value = NumberInput<int>.GetNumber("Enter a whole number");
long value = NumberInput<long>.GetNumber("Enter a non-negative whole number", min: 0);
float? value = NumberInput<float>.GetOptionalNumber("Enter a negative number (Press enter to skip)", max: 0);
decimal? value = NumberInput<decimal>.GetOptionalNumber("Enter a number between 0 and 100 (Press enter to skip)", min: 0, max: 100);
Retrieve option from the user

OptionInput is a class that allows for the retrieval of an option from the user. Default options can also be provided to make the input more user-friendly.

using IOUtils.Input;

string selectedOption = OptionInput.GetOption("Select an option", ["Option 1", "Option 2", "Option 3"]);
int optionIndex = OptionInput.GetOptionIndex("Select an option", ["Option 1", "Option 2", "Option 3"]);
bool doSomething = OptionInput.GetYesNoOption("Do you want to do something?");
bool tryAgain = OptionInput.GetEitherOrOption("What do you want to do?", "Try again", "Exit");
using IOUtils.Input;

string selectedOption = OptionInput.GetOption("Select an option", ["Option 1", "Option 2", "Option 3"], defaultOption: "Option 2");
int optionIndex = OptionInput.GetOptionIndex("Select an option", ["Option 1", "Option 2", "Option 3"], defaultOption: "Option 3");
bool doSomething = OptionInput.GetYesNoOption("Do you want to do something?", defaultOption: true);
bool tryAgain = OptionInput.GetEitherOrOption("What do you want to do?", "Try again", "Exit", defaultOption: true);

Alternatively, a dictionary can be used to map descriptions to values.

using IOUtils.Input;

Dictionary<string, int> options = new() {
    { "Option 1", 1 },
    { "Option 2", 2 },
    { "Option 3", 3 }
};

int selectedOption = OptionInput.GetOption("Select an option", options);
// Again, a default option can be provided if desired
selectedOption = OptionInput.GetOption("Select an option", options, defaultOption: "Option 2");

Console.WriteLine($"Value {selectedOption} returned");

Dictionary<string, Action> actions = new() {
    { "Option 1", () => Console.WriteLine("Option 1 selected") },
    { "Option 2", () => Console.WriteLine("Option 2 selected") },
    { "Option 3", () => Console.WriteLine("Option 3 selected") }
};

OptionInput.GetOption("Select an option", actions)();
OptionInput.GetOption("Select an option", actions, defaultOption: "Option 1")();
Retrieve file path from the user

FileInput is a class that allows for the retrieval of an existing file or directory path from the user.

using IOUtils.Input;

string filePath = FileInput.GetFilePath("Enter a file path");
string directoryPath = FileInput.GetDirectoryPath("Enter a directory path");

Encoding

Available encodings

The following encoders are available:

Encoder Character set
Encoder.Base2 0-1
Encoder.Base10 0-9
Encoder.Base16 0-9, A-F
Encoder.Base36 0-9, A-Z
Encoder.Base62 0-9, A-Z, a-z
Encoder.Base64 A-Z, a-z, 0-9, +, /
Encoder.Base64UriSafe A-Z, a-z, 0-9, -, _
Encode text

Encode a byte array using one of the available encoders. The encoded text is returned as a string.

using IOUtils.Data;

byte[] raw = "Hello, World!"u8.ToArray();

// Any encoder listed above can be used here
string encoded = Encoder.Base36.Encode(raw);

Console.WriteLine($"Encoded text: {encoded}");

To check if a byte array requires encoding, the RequiresEncoding method can be used:

using IOUtils.Data;

byte[] raw = "Hello, World!"u8.ToArray();

bool requiresEncoding = Encoder.Base36.RequiresEncoding(raw);
Decode text

Decode a string encoded using one of the available encoders. The decoded text is returned as a byte array. If the encoded text is not valid, a FormatException is thrown.

using IOUtils.Data;

string encoded = "FG3H7VQW7EEN6JWWNZMP";

byte[] decoded = Encoder.Base36.Decode(encoded);

Console.WriteLine($"Decoded text: {System.Text.Encoding.UTF8.GetString(decoded)}");

Contributions

Contributions are welcome! Read the CONTRIBUTING guide for information.

License

This project is licensed under the MIT License. See the LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.
  • net8.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.7.0 180 5/15/2024
1.6.1 189 4/26/2024
1.6.0 178 4/16/2024
1.5.0 181 4/12/2024
1.4.0 185 4/3/2024
1.3.0 174 3/29/2024
1.2.1 201 3/27/2024
1.2.0 198 2/17/2024
1.1.0 180 2/15/2024
1.0.1 188 2/13/2024
1.0.0 200 2/13/2024