68 questions
-2
votes
4
answers
141
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 ...
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
0
answers
165
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 ...
1
vote
1
answer
196
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
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 ...
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 ...
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 ...
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 ...
1
vote
1
answer
831
views
Read parameters of attribute created by source generator
I have the following source code generator
[Generator]
public class Generator : ISourceGenerator
{
public void Execute(GeneratorExecutionContext context)
{
var output = @"using ...
1
vote
0
answers
109
views
Resolving services for the IoC DI framework using source generation in opposed to System.Reflection
I like the idea of resolving services in the IoC using attributes. I wanted to replace System.Reflection with source generation, so it improves startup time.
The code snippet below is also on GitHub.
#...
2
votes
0
answers
179
views
C# Source Generators create codefix suggested edit
I have a source generator which creates a warning, I know how this warning would be fixed and could apply this fix automatically if given the opportunity.
https://github.com/dotnet/roslyn/blob/main/...
0
votes
1
answer
683
views
Can't access arguments of attribute from system library using source generator
I am trying to make a source generator for mapping columns from the google bigquery api client to class properties. I'm having trouble getting custom column names from a ColumnAttribute on the ...
0
votes
1
answer
487
views
How do I add location hints to C# source generation errors in generated classes?
I have a C# source generator that can come across configuration issues in the data it reads, these are emitted as compile errors. Currently this looks something like this:
DiagnosticDescriptor ...
7
votes
1
answer
2k
views
.NET 6 source generator - create classes within another project
I have 3 projects
Project A (Client)
Project B (Server)
Project C (Shared)
Within Project B I have the DB connection using the entity framework as well as all the entity classes, Project A (Client) ...
4
votes
2
answers
719
views
What is the functionality of IncrementalValuesProvider.WithTrackingName(string name)?
In the context of a .net6 incremental source generator, what does the IncrementalValuesProvider.WithTrackingName(string name) method do?
In addition how/when is it intended to be used?
[Generator]
...
5
votes
1
answer
3k
views
C# source generators: Is there a way to find type information of referenced projects?
Using C# source generators, is there a way to get more information about types in referenced assemblies. To be more precise: Is there a way to find out which type implements an interface that resides ...
1
vote
0
answers
599
views
How to use Roslyn to determine code's line and column position in a source file
I am using Roslyn within a source generator to find certain c# method calls in a syntax tree. When found, I want to note the line and column number.
This answer works for the line number but not the ...
3
votes
1
answer
2k
views
Access multiple projects from IIncrementalGenerator
I need to create code by the IIncrementalGenerator in at least two projects which are referring to the same library that references the SourceCodeGenerator project.
My solution, for further ...
7
votes
3
answers
9k
views
C# Incremental Generator - How I can read additional files? AdditionalTextsProvider not working as expected
I am trying to get some values from the appsettings.json. But whatever I try with the AdditionalTextsProvider doesn't work. Here is my code
IncrementalValuesProvider<AdditionalText> textFiles = ...
1
vote
1
answer
500
views
Are the results of `IncrementalValueProvider` extensions cached and compared?
SyntaxValueProvider.CreateSyntaxProvider takes two Func arguments: a predicate that filters the syntax elements, and a transform that returns the interesting details from the syntax context. The ...
3
votes
1
answer
1k
views
.NET 6 source generators and C# 9 syntax
If source generator projects must target netstandard2.0 (C# 7.3), how and why do the examples in the .NET 6 incremental generator documentation use C# 9 syntax like static anonymous functions?
From ...
2
votes
1
answer
646
views
How does the compiler pipeline correspond to Incremental Source Generation?
I'm having trouble understanding the Roslyn documentation and fiting it with what I see when working on an Incremental Source Generator.
https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/...
2
votes
1
answer
2k
views
Source generator with physical files on disk causing ambiguity
I'm working on a project where I want to generate cs classes based on JSON file that defines a set of exceptions. I looked into different options and trying source generator now. In my project, I want ...
4
votes
0
answers
2k
views
Incremental source generator not called in production build context
Given a working source generator and a working test project for the generator.
Generator
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>...
4
votes
2
answers
2k
views
How to fix source-code generator with .NET 6?
I ported my .NET 5.0 application to .NET 6.0 and now I found that the source-code generator fails. It shows the following error:
Generator 'PermissionGenerator' failed to generate source. It will not ...