ITLab.Template.DevPack.Helpers
Contains framework-light utility helpers for reflection, hashing, string manipulation, entity operations, permissions and domain support.
Componentes
| Tipo | Nome | Responsabilidade |
|---|---|---|
| Static Class | ColorHelper | Generates and maps color hex values from a built-in palette |
| Class | ConverterHelper | Converts objects to/from flat key-value dictionaries via reflection |
| Static Class | CultureHelper | Culture and localization support utilities |
| Static Class | CurrencyHelper | Active ISO 4217 codes (ActiveCodes, List One as of the 2026 amendments) and IsIso4217Code |
| Static Class | DateTimeHelper | Min/Max utilities for DateTime values |
| Static Class | DateTimeOffsetHelper | Min/Max utilities for DateTimeOffset values |
| Static Class | DocumentHelper | Brazilian fiscal document validation/normalization (IsCpfValid, IsCnpjValid, NormalizeCpf, NormalizeCnpj) |
| Static Class | DomainEventHelper | Domain-event lifecycle helper operations |
| Static Class | EntityHelper | Metadata inspection, equality, identifier assignment and diff utilities for entities |
| Static Class | EnumHelper | Enum metadata, value conversion utilities and TryParseStrict<TEnum> — the name matcher shared by StrictEnumJsonConverter<TEnum> and by query/route binding |
| Static Class | HashHelper | SHA-256 and other hashing utilities |
| Static Class | ObjectHelper | Reflective property assignment and object-to-dictionary conversion |
| Enum | EPermissionsGeneratorType | Output formats for permission generation: Json, TsUnion, TsShape |
| Static Class | PermissionsGenerator | Generates permission metadata from nested static classes (JSON object, TypeScript union type, TypeScript object shape) |
| Static Class | ReflectionHelper | Property discovery, type inspection and assignability utilities |
| Static Class | StaticHelper | Extracts constant fields and permission entries from types via reflection |
| Static Class | StringHelper | String generation, normalization and manipulation utilities |
| Static Class | TimeZoneHelper | IsIanaId: the id is an IANA time zone this host knows — what a browser's Intl accepts |
| Static Class | TypeHelper | Runtime type inspection and conversion utilities |
Nota de coabitação:
DateTimeHelpereDateTimeOffsetHelpervivem ambos emDateTimeHelper.cs(mesmo namespaceHelpers). O arquivo carrega as duas classes para manter um únicousingno consumidor.
Como usar
// Generate a random color for UI avatar assignment.
var hex = ColorHelper.GetRandomColor();
// Generate a TypeScript shape file from a nested permissions class at build time.
var ts = PermissionsGenerator.Generate(
typeof(MyAppPermissions),
EPermissionsGeneratorType.TsShape,
"Permissions");
File.WriteAllText("permissions.ts", ts);
// Compute entity diff for audit or change-tracking.
var changes = EntityHelper.GetChangedProperties(original, updated);
// Match an enum name the way the published contract declares it: case-insensitive, exact match
// first, and nothing else — no numeric form, no comma-separated combination, no undefined value.
if (!EnumHelper.TryParseStrict<EDocumentKind>(input, out var kind))
{
return DocumentErrors.UnknownKind(input);
}
// Validate a Brazilian CPF without throwing — useful for FluentValidation rules.
RuleFor(x => x.Cpf).Must(DocumentHelper.IsCpfValid).WithMessage("CPF inválido.");
// Normalize before persisting in a value object constructor.
var stored = DocumentHelper.NormalizeCpf("529.982.247-25"); // "52998224725"
// A value the SPA hands to Intl: an IANA zone and an active ISO 4217 code, nothing looser.
var zoneOk = TimeZoneHelper.IsIanaId("America/Sao_Paulo"); // true; "E. South America Standard Time" → false
var currencyOk = CurrencyHelper.IsIso4217Code("BRL"); // true; "brl", "XYZ", "ANG" (withdrawn) → false
O que não fazer
-
Do not use helpers as a dumping ground for domain-specific logic.
-
Do not add dependencies to heavy frameworks in this layer.
-
Do not use
ConverterHelperfor deep-graph serialization — it is flat-key-value only. -
TryParseStrictrejects a comma-separated value;StrictEnumJsonConverter<TEnum>(request body) still accepts it, because the built-in converter it derives from has no switch for it. That single input is the one place body and query disagree.Enum.IsDefineddoes not catch it when the members are contiguous — in{ Incluir = 1, Alterar = 2, Excluir = 3 },"Incluir,Alterar"meansExcluir. Disjoint values (1, 2, 4, 8, …) are what close it; the validator is the second half. See theJsonConvertersREADME. -
Do not call
Enum.TryParsewithignoreCase: truealone when the value crosses a contract boundary. It accepts the numeric form and any composable value, and it overrides even an exact match — inenum { aa, AA }it returnsaafor the input"AA", whileSystem.Text.JsonreturnsAA. UseEnumHelper.TryParseStrict<TEnum>. -
Do not validate a zone that reaches a browser with
OperatingWindows.BusinessTimeZone.TryResolve: it also accepts a Windows id and a fixed offset (UTC-03:00), andIntl.DateTimeFormatthrows on both. UseTimeZoneHelper.IsIanaId. -
TimeZoneHelper.IsIanaIdreads the host's time zone database (ICU on Windows,tzdataon Linux). A container image withouttzdata, or a host inInvariantGlobalization, refuses every id.
Extensão pelo produto
- Products should prefer composition over modifying shared helpers directly.
- New helper methods should stay pure or clearly document side effects.