68 questions
-2 votes
4 answers
143 views
How can I automatically inject common services into all command/query handlers without manually modifying each constructor?
I'm working on a .NET application where every command/query handler needs access to three shared services: IValidator, ISecurity and ILogger. Rather than manually injecting these into each handler ...
2 votes
0 answers
75 views
How to test .NET source generator with project reference and transitive NuGet dependencies?
I have a .NET analyzer (source generator) project referencing a NuGet package. I am trying to create an integration test project to test the source generator under real conditions. To accomplish this, ...
1 vote
1 answer
1k views
Get base class properties in C# source generation - IIncrementalGenerator
I have following Execute method in my source generator. I can get all the properties (x.Item1.Members.AsEnumerable()...) of my class. But I can't manage to get the properties of the base class too. ...
3 votes
2 answers
2k views
Get attribute property value in C# source generation - IIncrementalGenerator
I have following Attribute: [AttributeUsage(AttributeTargets.Class)] public class EventApplyAttribute : Attribute { public string Aggregate { get; } public EventApplyAttribute(string ...
3 votes
0 answers
168 views
Do C# code generators work in polyglot notebooks?
I would like to use a C# code generator for a polyglot notebook. (My eventual goal is to generate a strongly typed object model from a CSV or excel file I wish to analyze.) In an initial test I ...
4 votes
0 answers
1k views
Source generator is ignored by Visual Studio
I spent all day trying to run a Source Generator in Visual Studio 2022. I downloaded a few source code and none of them is working. Neither the Microsoft examples. I was trying to use a code to create ...
1 vote
1 answer
197 views
Hide embedded nuget files from VS solution explorer
I create my first Nuget Package of my incremental source generator. All was OK, targeting it as an analyzer in .csproj, embedded under analyzer/cs Nuget subfolders. But now I want to improve my ...
0 votes
0 answers
264 views
Get all usages of a TypeDeclerationSyntax in Incremental Source Generator
I have a generic class and i need to access all generic usages of that class using incremental source generators. My class is like: public class User<T> { public int Id { get; set; } ...
0 votes
0 answers
114 views
Flaky `ApplicationSyntaxReference` on `AttributeData` with (Incremental) Source Generator
Unfortunately, I have no minimal sample of the issue, but I've pushed the repo publicly, where it should be reproducable: https://github.com/Yeah69/ContainerFeatureSampleComparison I've implemented a ...
0 votes
0 answers
225 views
Use file from MAUI project to create a source file compile time in referenced project/package c#
I am stuck at this issue for sometime and looking for implementation ideas and/or code snippets. So I have 2 projects: A dotnet maui project which has a xml file. A class library which does something. ...
2 votes
1 answer
2k views
VS and Rider ignore source generator generated files
C# Source generated files are ignored or show errors but when I copy the file out everything works. state.Text.g.cs using System.Collections.Generic; using System.Linq; #nullable enable namespace ...
2 votes
1 answer
693 views
How to count generated lines of code in Visual Studio?
I'm working on a project in which the majority of the code is generated. I'm fully aware of what a useless metric SLOC is, but I'd like to brag about how much work and potential human error the code ...
0 votes
1 answer
140 views
Roslyn: Auto generating methods from controller routes
I wrote a Roslyn source generator that visits all of my controllers' methods that have an HttpGet, HttpPut, HttpDelete or HttpPost attribute on them, and then makes classes like this, that I was ...
1 vote
1 answer
202 views
GetOperation returning null for VariableDeclaratorSyntax, VariableDeclarationSyntax, and FieldDeclarationSyntax
In a C# incremental generator I am authoring, beginning from an ArgumentSyntax, I am trying to inspect the inline initializer for a readonly field referenced as a method argument. Understanding that ...
3 votes
2 answers
7k views
C# Source Generator not running
I want to create an incremental source generator that reads a json file and creates some classes out of it. Unfortunately, when I build my solution, no files are generated. Even the debugger statement ...