Netrilo.Infrastructure.Common.Extensions
1.0.2
There is a newer version of this package available.
See the version list below for details.
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" />
<PackageReference Include="Netrilo.Infrastructure.Common.Extensions" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=Netrilo.Infrastructure.Common.Extensions&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Netrilo.Infrastructure.Common.Extensions
Part of the Netrilo.Infrastructure SDK
๐ฆ 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 forSystem.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 | Versions 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.
-
net9.0
- DotEnvFile (>= 2.1.0)
- libphonenumber-csharp (>= 9.0.13)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.9)
- Newtonsoft.Json (>= 13.0.3)
- xunit.abstractions (>= 2.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.