Extensions
Overview
VersaTul.Extensions provides reusable extension methods for common collection, string, conversion, dictionary, and currency-related operations.
It acts as a convenience layer over other VersaTul packages, especially VersaTul.Utilities and VersaTul.Object.Converters.
When To Use This Package
Use this package when you want to:
Convert values and collections with concise extension syntax.
Normalize strings for naming or display.
Pick random items from a collection.
Convert objects into dictionaries or flattened representations.
Perform small currency-related transformations.
Installation
Install the package with the .NET CLI:
dotnet add package VersaTul.Extensions
Or with the Package Manager Console:
PM> NuGet\Install-Package VersaTul.Extensions -Version latest
Core Types And Concepts
ArrayExtensionsIncludes helpers such as
GetValue<T>()andPick<T>().CommonExtensionsIncludes string helpers such as
ToCamelCase(),ToCamelCaseSpan(),ToTitleCase(), andToTitleCaseSpan().ConvertExtensionsIncludes conversion helpers such as
To<T>(), collection conversion overloads,AsDictionary(), andAsFlattened().CurrencyExtensionsIncludes
RoundTo(),ToCurrency(),ToMicron(), andFromMicron().
Basic Example
These helpers are designed for direct, low-friction use in application code.
using VersaTul.Extensions;
var values = new List<string> { "1", "2", "3", "4" };
var integerValue = "123".To<int>();
var decimalValue = "123.22".To<decimal>();
var convertedValues = values.To<string, int>().ToList();
var picks = values.Pick(2).ToList();
var camel = "FirstName".ToCamelCase();
var title = "sample phrase".ToTitleCase();
Dictionary And Flattening Example
ConvertExtensions can project objects into dictionaries and flatten those dictionaries for export-style scenarios.
using VersaTul.Extensions;
var person = new Person
{
FirstName = "Bjorn",
LastName = "Williams",
Age = 37
};
var dictionary = person.AsDictionary();
var flattened = dictionary.AsFlattened();
Currency Example
using VersaTul.Extensions;
decimal amount = 123.4567m;
var rounded = amount.RoundTo(2);
var currency = amount.ToCurrency();
var micros = amount.ToMicron();
Notes
To<T>()and related conversion helpers delegate toCommonUtilityunder the hood.AsDictionary()andAsFlattened()are especially useful with export, reporting, and logging workflows.The span-based string helpers provide alternate implementations for text normalization scenarios.