Substantive.ComponentModel.SourceGenerators 9.17.10-build20260120r1
Substantive.ComponentModel.SourceGenerators
Incremental Roslyn generators that implement common metadata interfaces in the Substantive.ComponentModel stack. Each generator discovers partial classes or records annotated with a matching attribute and injects the interface implementation so you avoid repetitive boilerplate when modeling domain, data-transfer, or view models.
Included generators
| Attribute | Interface implemented | Members emitted |
|---|---|---|
SoftDeleteMetadataAttribute |
ISoftDeleteMetadata |
bool IsDeleted, DateTimeOffset? DeletedAt |
TimestampMetadataAttribute |
ITimestampMetadata |
DateTimeOffset CreatedAt, DateTimeOffset UpdatedAt (initialized to the same timestamp) |
SchemaVersionMetadataAttribute |
ISchemaVersionMetadata |
string SchemaVersion (defaults to "1") |
MultiTenantMetadataAttribute |
IMultiTenantMetadata |
string TenantId |
All generators share the same discovery rules:
- Targets must be
partialclasses or records. - Apply the corresponding attribute from
Substantive.ComponentModel. - Add
[IgnoreSourceGen](or derive fromIgnoreSourceGenAttribute) to opt out on a specific type.
Getting started
- Reference the analyzer NuGet in the consuming project (the generator compiles for
netstandard2.0, so it works on .NET Framework, .NET Core, .NET, and Xamarin/MAUI targets).<PackageReference Include="Substantive.ComponentModel.SourceGenerators" PrivateAssets="all" /> <PackageReference Include="Substantive.ComponentModel" /> - Mark eligible models as
partialand decorate them with the metadata attributes you need. - Build the project; the generator runs at compile time and emits the interface members into
*.g.csartifacts underobj/.
Usage example
using Substantive.ComponentModel;
[SoftDeleteMetadata]
[TimestampMetadata]
[SchemaVersionMetadata]
public partial record CaseFile
{
public Guid Id { get; init; }
public string Title { get; init; }
}
After compilation the partial record implements ISoftDeleteMetadata, ITimestampMetadata, and ISchemaVersionMetadata, so you can inject CaseFile into services that expect those contracts without hand-writing the repetitive properties.
Build, pack, and test
dotnet build src/BuildingBlocks/ComponentModel.SourceGenerators/ComponentModel.SourceGenerators.csprojcompiles analyzers and verifies Roslyn APIs.dotnet pack ... -c Releaseproduces a NuGet package that already includesreadme.mdandicon.png.- Add CI steps to copy the produced
Substantive.ComponentModel.SourceGenerators.dllintoanalyzers/dotnet/cs/inside the nupkg (the project file already configures this).
Troubleshooting
- Ensure consumers use the same version of
Substantive.ComponentModelso the attribute namespaces match the generator expectations. - Keep model files nullable-enabled; the generated members respect the project-wide
nullablecontext. - If you modify the attributes or interfaces, update the generator constants (
InterfaceTypeName/FullyQualifiedAttributeName) to keep them synchronized.
Showing the top 20 packages that depend on Substantive.ComponentModel.SourceGenerators.
| Packages | Downloads |
|---|---|
|
Substantive.Foundation.Backends
A metapackage contains all Substantive backend building blocks.
|
1 |
|
Substantive.Foundation.Backends
A metapackage contains all Substantive backend building blocks.
|
2 |
.NET Standard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 5.0.0)
- Microsoft.CodeAnalysis.Common (>= 5.0.0)