Devity.Extensions contains small helpers and extension methods for common .NET types, plus a simple string-template utility.
Install-Package Devity.ExtensionsMost APIs live under:
using Devity.Extensions;
using Devity.Extensions.Helpers;
using Devity.Extensions.Templates;Shorten(int maxLength): trims a string and appends...when needed.ToFormattedIban(): formats an IBAN into 4-character groups.Has(string needle): search helper that also compares normalized text.NormalizeForSearch(): lowercases text and removes spaces, punctuation, dashes, and diacritics.
var title = "Very long title".Shorten(8); // Very lon...
var iban = "CZ6508000000192000145399".ToFormattedIban();
var matches = "Příliš žluťoučký kůň".Has("zlutoucky kun");DateTime.ToHtmlDateString()DateTime.ToHtmlString()DateTime.ToReadableString()DateTime.ToReadableStringWithTime()DateTime.GetUntilEndOfDay()DateTime.GetUntilEndOfMonth()DateTime.IsWithinRange(start, end)IEnumerable<TimeSpan>.Sum()DateOnly.ToReadableString()
var htmlDate = DateTime.UtcNow.ToHtmlDateString();
var display = DateTime.Now.ToReadableStringWithTime();
var expiresIn = DateTime.Now.GetUntilEndOfDay();long.ToHumanReadableSize(): converts raw bytes toB,KiB,MiB, and so on.
var size = 15360L.ToHumanReadableSize(); // 15 KiBEnum.GetDisplayName(): readsDisplayAttribute.Namewhen present.ClassFacade.GetPropertyHumanName(PropertyInfo): display name fallback for properties.ClassFacade.GetCleanType(object): friendly type name, including generic arguments.
public enum Status
{
[Display(Name = "In progress")]
InProgress
}
var label = Status.InProgress.GetDisplayName();object.ToJson(bool indented = true): serializes withSystem.Text.Json.JsonHelper.INDENTED_OPTIONS: shared indented serializer options.
var json = new { Name = "Devity" }.ToJson();IQueryable<T>.DistinctByDb(...): database-friendlyDistinctByimplemented viaGroupBy(...).First().
var users = db.Users.DistinctByDb(x => x.Email);The template helper is a minimal file-based HTML/text templating system.
- Key replacement with
AddKey - Conditional block inclusion/exclusion with
AddCondition - Repeated block generation with
AddLoop
Template file:
<h1>-TITLE-</h1>
<p>Hello -NAME-</p>Usage:
var template = new DevityTemplate("Templates/welcome.html")
.AddKey("-TITLE-", "Welcome")
.AddKey("-NAME-", "Dave");
var html = template.PopulateTemplate();Use the same marker at the start and end of the section you want to conditionally keep.
-SHOW-ADMIN-
<p>Admin content</p>
-SHOW-ADMIN-template.AddCondition("-SHOW-ADMIN-", currentUser.IsAdmin);Use the same loop marker to wrap the repeated block.
-ITEMS-
<li>-NAME-: -PRICE-</li>
-ITEMS-var items = new List<CartItem>
{
new() { Name = "Book", Price = 10 },
new() { Name = "Pen", Price = 2 }
};
var loop = new DevityTemplateLoop<CartItem>(items)
.AddKey("-NAME-", x => x.Name)
.AddKey("-PRICE-", x => x.Price);
var template = new DevityTemplate("Templates/cart.html")
.AddLoop("-ITEMS-", loop);