Pyther.Core 0.2.2

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

// Install Pyther.Core as a Cake Tool
#tool nuget:?package=Pyther.Core&version=0.2.2

Pyther.Core

Library that provides logging functionality and extensions methods for strings and collections.

Logging

include namespace

using Pyther.Core.Logging;

add two example loggers

// a) Register a new console logger (with options)
Log.Register(new ConsoleLogger()
{
    MinLevel = LogLevel.Warning   // log Warning Level and above
});

// b) Register a new file logger (with options)
Log.Register(new FileLogger("path/to/file.log")
{
    AppendMode = true,            // append to exisiting file
    UseTimestamp = true,          // log timestamps
    MinLevel = LogLevel.Debug,    // log Debug Level and above
    Lock = true                   // make thread safe
});

log something

// Errors should inform about critical problems that can't be resolved by the system. 
Log.Error("This is a critical error!");

// Warnings should inform that something went wrong but can be handled by the system.
Log.Warning("This is a warning!");

// Infos should be enabled to display optional, relevant informations.
Log.Info("This is an information.");

// Process logging should be used to notify about important processes/steps.
Log.Process("This is a process.");

// Debug logging can be part of the final release, but should only be enabled when required to find problems.
Log.Debug("This is a debug message.");

/// Temporary logging should only be used during development and should completely be removed on final releases.
/// This kind of logging will always be executed. No matter what Log Level was chosen.
Log.Temp("Just log something temporary ...");

that's it 😃

Of course, you can use interpolated strings to log content of variables.

Log.Warning($"Sorry, I can`t divide {a} by {b}!");

This library comes with the following loggers:

  • ConsoleLogger ... log to the console using Console.Write
  • ConsoleColoredLogger ... log colored text to the console using Console.Write
  • DebugLogger ... Debug logger using Debug.Write
  • NullLogger ... simple no operation logger

It is easy to write your own logger ...

/// <summary>
/// A logger that show log messages using windows MessageBox.
/// </summary>
public class MessageBoxLogger : BaseLogger
{
    public override void Log(LogLevel level, string message)
    {
        System.Windows.MessageBox.Show(message);
    }
}

... and let it only show error messages:

Log.Register(new MessageBoxLogger()
{
    MinLevel = LogLevel.Error
});

String extensions

"abc".Repeat(3);  // result: "abcabcabc"
"abc".Reverse();  // result: "cba"
"Hello World".Clip(5);  // result: "Hello"
"abc".Base64Encode();  // result: "YWJj";
"YWJj".Base64Decode();  // result: "abc"

int? number = "123".Parse<int>();  // result: 123
FileMode? mode = "Append".Parse<FileMode>();  // result: FileMode.Append

FileMode? mode = "Append".ToEnum<FileMode>();  // result: FileMode.Append

DateTime? dateTime = "04/02/1981 10:51:17".ToDateTime();  // result: DateTime object

TimeSpan? timeSpan = "1:23:45".ToTimeSpan();  // result: TimeSpan object

Naming Policy Transformation

There are a bunch of transformation methods that can help to the switch between several naming policies.

// [snake_case -> ...]
"my_class_name".SnakeToTitleCase());  // "MyClassName"
"my_class_name".SnakeToCamelCase());  // "myClassName", 
"my_class_name".SnakeToKebabCase());  // "my-class-name", 

// [TitleCase/PascalCase -> ...]
"MyClassName".TitleToSnakeCase());    // "my_class_name", 
"MyClassName".TitleToKebabCase());    // "my-class-name", 
"MyClassName".TitleToCamelCase());    // "myClassName", 

// [kebabCase -> ...]
"my-class-name".KebabToTitleCase());  // "MyClassName", 
"my-class-name".KebabToSnakeCase());  //"my_class_name", 
"my-class-name".KebabToCamelCase());  //"myClassName", 

// [camelCase -> ...]
"myClassName".CamelToSnakeCase());    // "my_class_name", 
"myClassName".CamelToKebabCase());    //  "my-class-name", 
"myClassName".CamelToTitleCase());    // "MyClassName", 
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
0.2.2 131 1/16/2024
0.2.1 119 1/5/2024
0.2.0 108 12/26/2023
0.1.7 90 12/25/2023
0.1.6 96 12/20/2023
0.1.5 110 12/17/2023
0.1.4 102 12/11/2023
0.1.3 85 12/11/2023
0.1.2 98 12/10/2023