SeanOne.Iostream 1.0.2

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package SeanOne.Iostream --version 1.0.2
                    
NuGet\Install-Package SeanOne.Iostream -Version 1.0.2
                    
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="SeanOne.Iostream" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SeanOne.Iostream" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="SeanOne.Iostream" />
                    
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 SeanOne.Iostream --version 1.0.2
                    
#r "nuget: SeanOne.Iostream, 1.0.2"
                    
#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 SeanOne.Iostream@1.0.2
                    
#: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=SeanOne.Iostream&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=SeanOne.Iostream&version=1.0.2
                    
Install as a Cake Tool

IoStream for C#

Overview

IoStream is a lightweight C# library that aims to provide a set of chainable, highly readable input and output operations for console applications, simplifying the process of formatting output and validating input.

OutputStream

Overview

The OutputStream class is a static utility within the SeanOne.Iostream namespace that provides a comprehensive set of static methods for generating formatted console output. It supports printing various data types with built-in formatting options, customizable terminators, and configurable output patterns for collections and dictionaries.

Basic Usage

using SeanOne.Iostream;

// Simple chained printing
OutputStream.Print("Hello").Print("World", end:" ").Print(2023);
// Output: HelloWorld 2023

Core Methods

Print(object obj, string code="", string end = "")
using SeanOne.Iostream;

// Basic print with line ending
OutputStream.Print("First line", end:"\n").Print("Second line");
/* Output:
First line
Second line
*/

// Numeric formatting
OutputStream.Print(Math.PI, code:"/tostring:F2/end:!"); // "3.14!"
Print(IEnumerable collection, string code)
using SeanOne.Iostream;

var numbers = new List<int> {1, 2, 3};

// Collection printing
OutputStream.Print(numbers, code:"fe/end:, "); 
// Output: 1, 2, 3, 

// Exclude last separator
OutputStream.Print(numbers, code:"fe/end:, /exclude-last-end:true");
// Output: 1, 2, 3
PrintLine Methods
PrintLine()
using SeanOne.Iostream;

OutputStream.PrintLine() // Prints a new line
PrintLine(object obj, string code = "")
using SeanOne.Iostream;

// Basic print with line ending
OutputStream.PrintLine("First line").Print("Second line");
/* Output:
First line
Second line
*/

// Numeric formatting
OutputStream.PrintLine(Math.PI, code:"/tostring:F2/end:!"); // "3.14!"
Formatting with Code Parameter

The code parameter is processed by the CodeTranslator class and supports various formatting directives:

Common Parameters
Parameter Example Description
/end: /end:\\n Appended after each value. Use Regex.Unescape() to decode it
/exclude-last-end: /exclude-last-end:true Omits terminator for last item
/tostring: /tostring:F2 An object that implements the IFormattable interface is required in order to perform formatting operations.
Dictionary-Specific
Parameter Example Description
/dicformat: /dicformat:{0}=>{1} Dictionary output format. {0} is key, {1} is value
/keyformat: /keyformat:F2 Dictionary key format string
/valueformat: /valueformat:F2 Dictionary value format string
using SeanOne.Iostream;

var dict = new Dictionary<int, string>{{1,"A"},{2,"B"}};

OutputStream.Print(dict, 
    code:"fe /dicformat:{0}={1} /end:; /keyformat:D2 /valueformat:%-3s /exclude-last-end:true");
// Output: 01=A;02=B
Examples
1. Formatted Number List
using SeanOne.Iostream;

double[] values = { 1.2, 3.4, 5.6 };
OutputStream.Print(values, code:"fe/end:\" | \" /tostring:F1 /exclude-last-end:true");
// Output: 1.2 | 3.4 | 5.6
2. Multi-line Output
using SeanOne.Iostream;

OutputStream.PrintLine("Results:")
           .Print(new[]{1,2,3}, code:"fe/end:\\n")
           .Print("End");
/* Output:
Results:
1
2
3
End
*/
3. Special Characters
using SeanOne.Iostream;

OutputStream.Print("Separated", code:"/end:\\u2026"); // "Separated…"
Error Handling
using SeanOne.Iostream;

try {
    OutputStream.Print("Text", code:"/tostring:F2"); // Throws ArgumentException
}
catch (ArgumentException ex) {
    Console.WriteLine($"Error: {ex.Message}");
}
Best Practices
  1. Chain calls for complex output:

     using SeanOne.Iostream;
    
     OutputStream.Print("Start: ", end:"")
               .Print(items, code:"fe/end:, ")
               .PrintLine(); // Force final newline
    
  2. Pre-format values when possible:

    using SeanOne.Iostream;
    
    string formatted = $"{value:F2}";
    OutputStream.Print(formatted);
    
  3. Use /exclude-last-end:true for clean collection formatting

InputStream

Overview

The InputStream class is part of the SeanOne.Iostream namespace and provides a comprehensive set of static methods for reading validated user input from the console. It supports reading various data types with built-in validation, customizable error messages, and configurable console colors for error display.

Usage Examples

Basic Usage
using SeanOne.Iostream;

// Read a string
string name = InputStream.GetString();

// Read an integer with default error handling
int age = InputStream.GetInt();

// Read a decimal with custom error message
decimal price = InputStream.GetDecimal("Please enter a valid decimal number");
Advanced Usage
using SeanOne.Iostream;

// Set global error message and color
InputStream.ErrorMessage = "Invalid input detected!";
InputStream.ErrorConsoleForeColor = ConsoleColor.Red;

// Read input (will use global settings)
double value = InputStream.GetDouble();

// Reset global settings
InputStream.ResetPublicVariables();

// Read with specific error message and color
int quantity = InputStream.GetInt(
    "Please enter a valid integer", 
    ConsoleColor.Yellow
);

API Reference

Properties
  • ErrorMessage: Global error message string
  • ErrorConsoleForeColor: Global error message color
Utility
  • ResetPublicVariables(): Resets the global error message to an empty string and the error console color to null, restoring default behavior.
Methods
Input Methods

The class provides methods for reading various data types including: GetString(), GetInt(), GetLong() etc

Each method has overloads that allow customization of error messages and console colors.

Utility
  • ResetPublicVariables(): Resets global error message and color to default values

Notes

  • All methods will continuously prompt until valid input is provided
  • Method-specific error messages override global error messages
  • Console colors are automatically restored after displaying error messages
  • The class handles different line ending formats (\r, \n, and \r\n)

Example Program

using System;
using SeanOne.Iostream;

class Program
{
    static void Main()
    {
        OutputStream.PrintLine("Please enter your name:");
        string name = InputStream.GetString();
        
        OutputStream.PrintLine("Please enter your age:");
        int age = InputStream.GetInt("Invalid age. Please enter a number:");
        
        OutputStream.PrintLine("Please enter your height (in meters):");
        decimal height = InputStream.GetDecimal(
            "Invalid height format. Please use decimal format (e.g., 1.75):", 
            ConsoleColor.Red
        );
        
        OutputStream.PrintLine($"Hello {name}, you are {age} years old and {height}m tall.");
    }
}

Limitations

  • Primarily designed for console applications
  • Performance may be impacted when processing very large collections
  • Some formatting options may not be available on all platforms

Contributing

This is a personal project, but feedback and suggestions are welcome.

License

This library is provided under the MIT License.

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 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.  net7.0-windows7.0 is compatible.  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.  net8.0-windows7.0 is compatible.  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.  net9.0-windows7.0 is compatible.  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 is compatible.  net471 is compatible.  net472 is compatible.  net48 is compatible.  net481 is compatible. 
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.
  • .NETFramework 4.7

    • No dependencies.
  • .NETFramework 4.7.1

    • No dependencies.
  • .NETFramework 4.7.2

    • No dependencies.
  • .NETFramework 4.8

    • No dependencies.
  • .NETFramework 4.8.1

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net7.0-windows7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net8.0-windows7.0

    • No dependencies.
  • net9.0

    • No dependencies.
  • net9.0-windows7.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