Some problems that should be solved:
1 How to know that the user opted for this generation ? Of course , with an attribute – I named mine GenerateDbContextExistsAttribute
( consequence: The problem of multiple assemblies sharing same attribute is solved – see Andrew Lock https://andrewlock.net/exploring-dotnet-10-preview-features-4-solving-the-source-generator-marker-attribute-problem-in-dotnet-10/ )
2. The generation of function : the function that returns true / false if the table exists ( the longcount returns data) should be generated either via a template , either from code ). For simplicity, I opted for direct code
3. Must have some diagnostics ( if the class is partial , if the attribute is on a class that inherits from DBContext …)
4. Must have tests
Other than that , is a normal Roslyn Code Generator
Tomorrow about how to use it.
NuGet package: RSCG_DBContext | GitHub repository