Plinth.Common 1.5.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
.NET 6.0
dotnet add package Plinth.Common --version 1.5.0
NuGet\Install-Package Plinth.Common -Version 1.5.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="Plinth.Common" Version="1.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Plinth.Common --version 1.5.0
#r "nuget: Plinth.Common, 1.5.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Plinth.Common as a Cake Addin
#addin nuget:?package=Plinth.Common&version=1.5.0

// Install Plinth.Common as a Cake Tool
#tool nuget:?package=Plinth.Common&version=1.5.0

README

Plinth.Common

A set of generic utilities, extensions, and enhancements for dotnet applications

Cache

Extensions for atomic GetOrCreate on Microsoft.Extensions.Caching.Memory memory caches Example:

IMemoryCache memCache = MemoryCacheUtil.Create();
await memCache.GetOrCreateAtomicMaxDurationAsync(
	"key", TimeSpan.FromMinutes(2), async () => await LoadValue());

👉 MemoryCacheUtil.Create() is a shorthand method for creating a new IMemoryCache.

Collections

  • Case Insensitive Dictionary and HashSet
  • Default Dictionary that will supply a default value for a key when requested
  • Examples:
// values are case insensitive
var set = new CaseInsensitiveHashSet<string>() { "abc", "ABC" };
set.Contains("aBc"); // true

// LINQ extension
var set = items.Where(...).Select(...).ToCaseInsensitiveHashSet();

// keys are case insensitive
var dict = new CaseInsensitiveDictionary<string, int>() { ["abc"] = 5 };
dict["ABC"]; // 5
dict.ContainsKey("aBc"); // true

// LINQ extension
var dict = items.Where(...).Select(...).ToCaseInsensitiveDictionary(v => v.ID);

// default dictionary, easy counting
var dict = new DefaultDictionary<string, int>(0);
dict["a"]++; // dict["a"] now is 1

// default dictionary, easy multi maps
var dict = new DefaultDictionary<string, ISet<int>>(() => new HashSet<int>());
dict["a"].Add(7); // "a" has a set with (7) in it

Constants

Handy constants for Content Types ContentTypes.ApplicationJson"application/json; charset=utf-8"

Exceptions

Logical exceptions for common API return values. Allows for separation between logic and api projects

  • LogicalBadRequestException
  • LogicalConflictException
  • LogicalForbiddenException
  • LogicalNotFoundException
  • LogicalPreconditionFailedException

Extensions

A variety of useful extensions to common classes

  • For manipulating DataRow
  • IDictionary .GetValueOrDefault()
  • IEnumerable .IsNullOrEmpty() and .Many()
  • Enum extensions for converting between enums by name (not by integer value)
  • ILogger extensions for logging code durations
using (log.LogExecTiming("some code"))
{
	... some code ...
	log.Debug("action");
}
// logs
[CTX-6540F] : Starting some code #52400089
[CTX-6540F] : action
[CTX-6540F] : some code #52400089 Took: 00.00.00.274472
  • Sensitive data extensions for masking secure items like passwords, SSNs, and credit card numbers.
  • Stream extensions .ToBytes() and .ToBytesAsync()
  • String extensions for converting strings to various types, .ChangeType<T>() as various .To{Type}OrNull()

Logging

  • Extensions and enhancements to Microsoft.Extensions.ILogger for better tracing when using the Plinth ecosystem
  • Provides StaticLogManager.GetLogger() to retrieve a static logger for the current class
  • Provides RequestTraceId and RequestTraceProperties singletons for passing data through the entire call stack (including across HTTP boundaries)
  • Adds shorthand calls for shorter log function names.
    • LogTraceTrace
    • LogDebugDebug
    • LogInformationInfo
    • LogWarningWarn
    • LogErrorError
    • LogCriticalCritical or Fatal

Mapping

An enhanced version of Omu.ValueInjecter for easy object to object mapping Allows for deeply nested Field to Field mapping (including Lists, Sets, and Dictionaries)

Utils

A set of static utilities

  • AsyncUtil: Some async utilities, mostly obsolete as of .NET 6
  • DateTimeUtil: Utilities for truncating date times, UTC/TZ conversions, and some date comparison functions
  • HexUtil: Conversion of hex strings to bytes and vice versa. E.g. "1a5b" <=> new byte[] { 0x1a, 0x5b }
  • RuntimeUtil: Provides FindExecutableHome() which can find your project root at runtime
  • TimeUtil: Provides log timing (used by ILogger extension noted above)
  • UriUtil: Provides a Join() method similar to Path.Combine()
Product Versions
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (17)

Showing the top 5 NuGet packages that depend on Plinth.Common:

Package Downloads
Plinth.Serialization The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

JSON/XML/etc object serialization

Plinth.Security The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Security, Cryptography, and Token Utilities

Plinth.HttpApiClient The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

HTTP Api Client framework built on MS HttpClient

Plinth.AspNetCore The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Plinth ASP.NET Core Services Utilities

Plinth.Serialization.RestSharp The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

JSON/XML/etc object serialization RestSharp

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.5.0 414 11/9/2022
1.5.0-b88.7a7c20cd 35 11/9/2022
1.4.7 2,191 10/20/2022
1.4.6 1,809 10/17/2022
1.4.5 2,229 10/1/2022
1.4.4 2,293 8/16/2022
1.4.3 2,225 8/2/2022
1.4.2 2,438 7/19/2022
1.4.2-b80.7fdbfd04 72 7/19/2022
1.4.2-b74.acaf86f5 121 6/15/2022
1.4.1 2,653 6/13/2022
1.4.0 2,376 6/6/2022
1.3.8 4,405 4/12/2022
1.3.7 2,473 3/21/2022
1.3.6 2,419 3/17/2022
1.3.6-b67.ca5053f3 75 3/16/2022
1.3.6-b66.4a9683e6 67 3/16/2022
1.3.5 2,416 2/23/2022
1.3.4 2,865 1/20/2022
1.3.3 1,539 12/29/2021
1.3.2 1,547 12/11/2021
1.3.1 1,715 11/12/2021
1.3.0 1,822 11/8/2021
1.2.3 3,208 9/22/2021
1.2.2 2,290 8/20/2021
1.2.1 2,556 8/5/2021
1.2.0 4,233 8/1/2021
1.2.0-b37.a54030b9 110 6/24/2021
1.1.6 9,401 3/22/2021
1.1.5 2,397 3/9/2021
1.1.4 3,374 2/27/2021
1.1.3 1,934 2/17/2021
1.1.2 1,965 2/12/2021
1.1.1 2,256 2/1/2021
1.1.0 2,022 12/16/2020
1.1.0-b27.b66c309b 235 11/15/2020
1.0.12 3,647 10/18/2020
1.0.11 2,049 10/6/2020
1.0.10 2,150 9/30/2020
1.0.9 2,134 9/29/2020
1.0.8 2,118 9/26/2020
1.0.7 2,055 9/19/2020
1.0.6 1,968 9/3/2020
1.0.5 2,195 9/2/2020
1.0.4 2,321 9/1/2020
1.0.3 1,927 9/1/2020
1.0.2 1,976 8/29/2020
1.0.1 1,952 8/29/2020
1.0.0 1,960 8/29/2020
1.0.0-b1.c22f563d 199 8/28/2020

net7.0 support and removed netcoreapp3.1