Expert guidance for MetaTypes C# source generator - compile-time metadata, vendor system, DI integration, and diagnostic analyzers
Expert guidance for working with the MetaTypes C# source generator project - a vendor-based architecture for compile-time metadata generation.
Provides comprehensive assistance with the MetaTypes project:
MetaTypes is a C# source generator that produces compile-time metadata for classes, structs, records, and enums to reduce reflection overhead. It implements a pluggable vendor system allowing custom type discovery and metadata extensions.
**Key Architecture:**
When exploring the codebase:
1. Read `src/MetaTypes.Abstractions/CLAUDE.md` for core interfaces and attributes
2. Check `src/MetaTypes.Generator.Common/CLAUDE.md` for shared infrastructure
3. Review vendor-specific docs:
- `samples/Vendor/EfCore/CLAUDE.md` for Entity Framework integration
- `samples/Vendor/Statics/CLAUDE.md` for static method repositories
Start with these commands to understand features:
```bash
cd samples/Vendor/EfCore/Sample.EfCore.SingleProject
dotnet run
cd samples/Sample.Console
dotnet run
cd samples/Vendor/EfCore/Sample.EfCore.MultiProject
dotnet run
```
Create or modify `metatypes.config.json` in the project root:
```json
{
"MetaTypes.Generator": {
"Generation": { "BaseMetaTypes": true },
"Discovery": {
"CrossAssembly": true,
"Methods": ["MetaTypes.Attribute", "MetaTypes.Reference"]
}
}
}
```
**Key settings:**
**EfCore Vendor Features:**
**Statics Vendor Features:**
When adding vendor functionality:
1. Define vendor-specific attributes in Abstractions
2. Implement discovery logic in vendor folder
3. Add diagnostic analyzers for validation
4. Update vendor CLAUDE.md documentation
When adding new diagnostics:
1. **Define descriptor** in vendor diagnostics file (e.g., `StaticsDiagnostics.cs`):
```csharp
public static readonly DiagnosticDescriptor MTSTAT0001 = new(
id: "MTSTAT0001",
title: "Rule title",
messageFormat: "Message format",
category: "MetaTypes.Statics",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true
);
```
2. **Update `AnalyzerReleases.Unshipped.md`** with new rule entry
3. **Document in `docs/DIAGNOSTICS.md`** with examples and fixes
4. **Test** in IDE for real-time validation
**Diagnostic ID Convention:** `MT{VendorPrefix}{Number}`
Generated methods follow target namespace:
**Cross-Assembly Mode:**
```csharp
services.AddMetaTypesSampleConsole(); // Unified registration
```
**Single-Project Mode:**
```csharp
services.AddMetaTypesSampleBusiness();
services.AddMetaTypesSampleAuth();
```
**Vendor-Specific:**
```csharp
services.AddMetaTypesSampleConsoleEfCore();
services.AddMetaTypesSampleConsoleStatics();
services.AddMetaTypesSampleConsoleStaticsRepositories();
```
```bash
dotnet build
dotnet test
dotnet build samples/
dotnet clean && dotnet build
```
Follow this workflow:
1. **Design** - Review existing vendor patterns
2. **Implement** - Add to appropriate layer (Abstractions, Common, or Generator)
3. **Diagnose** - Add analyzers for validation
4. **Document** - Update CLAUDE.md and docs/
5. **Test** - Add sample project demonstrating feature
6. **Release tracking** - Update AnalyzerReleases files
**Add a new vendor:**
1. Create folder in `samples/Vendor/{VendorName}/`
2. Add CLAUDE.md documentation
3. Implement discovery and generation logic
4. Add diagnostic analyzers
5. Create sample projects
**Debug source generator:**
1. Set breakpoint in generator code
2. Attach debugger to `dotnet build` process
3. Or use `System.Diagnostics.Debugger.Launch()` in generator
**Extend metadata:**
1. Add properties to MetaType partial class
2. Update vendor-specific generation logic
3. Add diagnostic validation if needed
**Fix diagnostic warnings:**
1. Check `docs/DIAGNOSTICS.md` for rule explanation
2. Apply suggested fix or suppress with `#pragma warning disable MTXXX`
3. Update `.editorconfig` for project-wide suppression
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/metatypes-project-guide/raw