Netrilo.Infrastructure.Common.Extensions 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Netrilo.Infrastructure.Common.Extensions --version 1.0.2
                    
NuGet\Install-Package Netrilo.Infrastructure.Common.Extensions -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="Netrilo.Infrastructure.Common.Extensions" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Netrilo.Infrastructure.Common.Extensions" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Netrilo.Infrastructure.Common.Extensions" />
                    
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 Netrilo.Infrastructure.Common.Extensions --version 1.0.2
                    
#r "nuget: Netrilo.Infrastructure.Common.Extensions, 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 Netrilo.Infrastructure.Common.Extensions@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=Netrilo.Infrastructure.Common.Extensions&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Netrilo.Infrastructure.Common.Extensions&version=1.0.2
                    
Install as a Cake Tool

Netrilo.Infrastructure.Common.Extensions

Part of the Netrilo.Infrastructure SDK

๐Ÿ“ฆ NuGet

NuGet

๐Ÿ“– Overview

Netrilo.Infrastructure.Common.Extensions is a collection of extension methods, utilities, validators, and infrastructure helpers for .NET applications.

It provides ready-to-use helpers for:

  • String manipulation (case conversions, hashing)
  • Object โ†’ QueryString conversion
  • Path utilities
  • JSON converters
  • Environment variable handling
  • Strongly typed settings
  • Logging
  • Input validation (e.g., mobile numbers)
  • ...

โœจ Features

๐Ÿ”ง Extensions

  • ByteArray
    • Sha256: Compute SHA-256 hash for byte arrays.
  • Object
    • QueryString: Convert objects into query string format.
  • String
    • ToCamelCase, ToPascalCase, ToSnakeCase, ToKebabCase, ToTrainCase.
    • Sha256: Compute SHA-256 hash from a string.
    • StringExtensions: Additional helpers for null/empty checks and transformations.

๐Ÿ›  Path Utilities

  • PathUtilitiesExtension: Normalize and validate file paths.
  • Custom exception: InvalidDirectorySeperatorCharException.

โš™๏ธ Settings

  • AppSettingsBase: Base class for strongly-typed app settings.
  • Interfaces: IAppSettings, IGlobalSettings, IWorkerSettings.

๐Ÿ“ Tools

  • DotEnv loader for environment variables (.env files).
  • [EnvName] attribute for mapping environment variables to properties.
  • Exceptions for missing environment variables.

๐Ÿงพ JSON Converters

  • MailAddressConverter: JSON support for System.Net.Mail.MailAddress.

๐Ÿชต Logger

  • AppLogger: lightweight structured logger for apps and services.

โœ… Validators

  • ValidationBase.IsValidMobileNumber(ulong): Validates international mobile numbers using libphonenumber-csharp.

๐Ÿš€ Getting Started

Prerequisites

  • .NET 8.0+ or .Net Standard 2.0

Installation

Install from NuGet:

dotnet add package Netrilo.Infrastructure.Common.Extensions

Or reference the project in your solution.


๐Ÿ“˜ Usage Examples

๐Ÿ”‘ String Case Conversions

using Netrilo.Infrastructure.Common.Extensions.String;

"hello world".ToCamelCase();   // "helloWorld"
"hello world".ToPascalCase();  // "HelloWorld"
"hello world".ToSnakeCase();   // "hello_world"
"hello world".ToKebabCase();   // "hello-world"
"hello world".ToTrainCase();   // "Hello-World"

๐Ÿ”‘ Hashing

using Netrilo.Infrastructure.Common.Extensions.String;

string password = "Secret123";
string hash = password.ToSha256();
using Netrilo.Infrastructure.Common.Extensions.ByteArray;

byte[] data = Encoding.UTF8.GetBytes("Hello");
string hash = data.ToSha256();

๐Ÿ”‘ Object โ†’ Query String

using Netrilo.Infrastructure.Common.Extensions.Object;

var user = new { Name = "Alice", Age = 30 };
string qs = user.ToQueryString();
// "Name=Alice&Age=30"

๐Ÿ”‘ Path Utilities

using Netrilo.Infrastructure.Common.Extensions.PathUtilities;

string path = "C:/invalid\\path";
string normalized = path.NormalizeDirectorySeparators();

๐Ÿ”‘ Settings

public class DbSettings : AppSettingsBase, IAppSettings
{
    public string ConnectionString { get; set; }
}

๐Ÿ”‘ Environment Variables

using Netrilo.Infrastructure.Common.Extensions.Tools;

DotEnv.Load(".env");
string dbHost = Environment.GetEnvironmentVariable("DB_HOST");

With annotations:

public class DbConfig
{
    [EnvName("DB_HOST")]
    public string Host { get; set; }
}

๐Ÿ”‘ JSON Converter

var options = new JsonSerializerOptions();
options.Converters.Add(new MailAddressConverter());

var mail = new MailAddress("user@example.com");
string json = JsonSerializer.Serialize(mail, options);

๐Ÿ”‘ Logger

var logger = new AppLogger();
logger.Info("Application started");
logger.Error("Unexpected error", ex);

โœ… Validators

using Netrilo.Infrastructure.Common.Extensions.Validators;

ulong number = 14155552671; // US number
bool valid = ValidationBase.IsValidMobileNumber(number);
Console.WriteLine(valid); // true if valid

๐Ÿงช Tests

Run the following command to run the tests:

dotnet test .\Tests\Netrilo.Infrastructure.Common.Extensions.UnitTests\Netrilo.Infrastructure.Common.Extensions.UnitTests.csproj

๐Ÿ“„ License

MIT License

Product Compatible and additional computed target framework versions.
.NET 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.  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.

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.0.4 193 9/15/2025
1.0.3 183 9/15/2025
1.0.2 59 9/12/2025
1.0.1 65 9/12/2025