Guidance for Claude Code when working in this repository.
AltaSoft.DomainPrimitives is a C# toolkit built around a Roslyn incremental source generator. Consumers declare a readonly partial struct/partial class implementing IDomainValue<T> with a Validate(T value) method; the generator emits the constructor, TryCreate, operators, IParsable<T>, IConvertible, JsonConverter, TypeConverter, XML serialization, Swagger/OpenAPI mappings, etc. See README.md for the full user-facing feature set — keep it in sync with generator behavior when either changes.
src/AltaSoft.DomainPrimitives— core attributes, base types (PrimitiveValidationResult,InvalidDomainValueException, etc.) and the*Extensionsflexible-parsing helpers (DateOnlyExtensions,DateTimeExtensions,DateTimeOffsetExtensions,TimeOnlyExtensions,TimeSpanExtensions).src/AltaSoft.DomainPrimitives.Generator— the incremental source generator itself (DomainPrimitiveGenerator.cs,Executor.cs,Helpers/*,Models/*).src/AltaSoft.DomainPrimitives.XmlDataTypes— ready-made XML Schema primitive types (GDay,GMonth,GYear,NonEmptyString, etc.) built on top of the generator.src/AltaSoft.DomainPrimitives.SwaggerExtensions/src/AltaSoft.DomainPrimitives.OpenApiExtensions— Swashbuckle and Microsoft.AspNetCore.OpenApi integration.tests/AltaSoft.DomainPrimitives.UnitTests— behavioral tests against generated code.tests/AltaSoft.DomainPrimitives.Generator.Tests— Roslyn generator snapshot tests using Verify (*.verified.csfiles underSnapshots/).tests/AltaSoft.DomainPrimitives.XmlDataTypes.Tests— tests for the XML data types package.Examples/— a demo API project and standalone example domain types (DomainPrimitivesDemo/).
dotnet build AltaSoft.DomainPrimitives.sln
dotnet test AltaSoft.DomainPrimitives.sln
Target frameworks are net8.0, net9.0, net10.0 (Directory.Build.props); LangVersion is Latest. When changing generator output, regenerate/update Verify snapshots by running the generator tests and accepting the new .verified.cs output — never hand-edit a .verified.cs file to match new code without confirming the generated output is actually correct.
Do not commit bin//obj//.vs/ — clean.bat wipes them locally if needed.
- No explicit constructors, public properties, or public fields on
IDomainValue<T>implementations — the generator owns those and will emit compiler errors on violations (this is by design, not a bug to "fix"). - Generated code lives in
*.g.cs; never hand-edit generated output — change the generator instead. SerializationFormatAttributeand theIsDateOrTime()-gated codegen inMethodGeneratorHelper.csare the two places that decide whetherParse/TryParsefor date/time-backed primitives use plain.Parse/.TryParsevs. the flexibleParseFlexible/TryParseFlexiblehelpers — check both when touching date/time parsing behavior.- Match existing XML doc style (
<summary>,<param>,<returns>,<inheritdoc/>where applicable) —GenerateDocumentationFileis enabled and analyzers run atAnalysisLevel=latest. - Follow this repo's own no-unnecessary-comments style; prefer expressive names over comments in new code.
When adding or changing user-facing generator behavior (new attributes, new supported underlying types, new generation flags, parsing behavior changes), update:
README.md(What's New, the relevant feature section, and the table of contents)EntityFrameworkCoreExample.mdif EF Core value-converter behavior is affected