Pular para o conteúdo principal
Versão: main (dev) 🚧

ITLab.Template.DevPack.Helpers

Contains framework-light utility helpers for reflection, hashing, string manipulation, entity operations, permissions and domain support.

Componentes​

TipoNomeResponsabilidade
Static ClassColorHelperGenerates and maps color hex values from a built-in palette
ClassConverterHelperConverts objects to/from flat key-value dictionaries via reflection
Static ClassCultureHelperCulture and localization support utilities
Static ClassCurrencyHelperActive ISO 4217 codes (ActiveCodes, List One as of the 2026 amendments) and IsIso4217Code
Static ClassDateTimeHelperMin/Max utilities for DateTime values
Static ClassDateTimeOffsetHelperMin/Max utilities for DateTimeOffset values
Static ClassDocumentHelperBrazilian fiscal document validation/normalization (IsCpfValid, IsCnpjValid, NormalizeCpf, NormalizeCnpj)
Static ClassDomainEventHelperDomain-event lifecycle helper operations
Static ClassEntityHelperMetadata inspection, equality, identifier assignment and diff utilities for entities
Static ClassEnumHelperEnum metadata, value conversion utilities and TryParseStrict<TEnum> — the name matcher shared by StrictEnumJsonConverter<TEnum> and by query/route binding
Static ClassHashHelperSHA-256 and other hashing utilities
Static ClassObjectHelperReflective property assignment and object-to-dictionary conversion
EnumEPermissionsGeneratorTypeOutput formats for permission generation: Json, TsUnion, TsShape
Static ClassPermissionsGeneratorGenerates permission metadata from nested static classes (JSON object, TypeScript union type, TypeScript object shape)
Static ClassReflectionHelperProperty discovery, type inspection and assignability utilities
Static ClassStaticHelperExtracts constant fields and permission entries from types via reflection
Static ClassStringHelperString generation, normalization and manipulation utilities
Static ClassTimeZoneHelperIsIanaId: the id is an IANA time zone this host knows — what a browser's Intl accepts
Static ClassTypeHelperRuntime type inspection and conversion utilities

Nota de coabitação: DateTimeHelper e DateTimeOffsetHelper vivem ambos em DateTimeHelper.cs (mesmo namespace Helpers). O arquivo carrega as duas classes para manter um único using no 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 ConverterHelper for deep-graph serialization — it is flat-key-value only.

  • TryParseStrict rejects 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.IsDefined does not catch it when the members are contiguous — in { Incluir = 1, Alterar = 2, Excluir = 3 }, "Incluir,Alterar" means Excluir. Disjoint values (1, 2, 4, 8, …) are what close it; the validator is the second half. See the JsonConverters README.

  • Do not call Enum.TryParse with ignoreCase: true alone when the value crosses a contract boundary. It accepts the numeric form and any composable value, and it overrides even an exact match — in enum { aa, AA } it returns aa for the input "AA", while System.Text.Json returns AA. Use EnumHelper.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), and Intl.DateTimeFormat throws on both. Use TimeZoneHelper.IsIanaId.

  • TimeZoneHelper.IsIanaId reads the host's time zone database (ICU on Windows, tzdata on Linux). A container image without tzdata, or a host in InvariantGlobalization, 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.