Welcome to RoslynAndInterceptors
Press space to navigate.
Press left arrow to go back.
Press right arrow to go forward.
For content please see up menu ▲
Online at https://ignatandrei.github.io/Presentations/RoslynAndInterceptorsprez.html
For download https://ignatandrei.github.io/Presentations/RoslynAndInterceptors.zip

						System.Console.WriteLine("Ignat Andrei");
						System.Console.WriteLine("RoslynAndInterceptors");							
						  

ignat Andrei Ignat http://msprogrammer.serviciipeweb.ro/

YouTube 5 minutes .NET and tools : http://bit.ly/5MinTools

Book Making Open Source Component : http://bit.ly/NetOpenSourceComponent

Book Copy Paste from StackOverflow : https://amzn.to/2PQ8EDc

Roslyn Source Code Generators with examples : https://ignatandrei.github.io/RSCG_Examples/

Monthly meetings: https://www.meetup.com/Bucharest-A-D-C-E-S-Meetup/

For notes press S
For print ?print-pdf
For all slides press ESC
https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/
roslyn
Demo : Wait.sln ,https://www.nuget.org/packages/RSCG_WaitAndOptions
Demo : RSCG_TimeBombComment.sln , https://www.nuget.org/packages/RSCG_TimeBombComment

						var syntax = context
							.SyntaxProvider.CreateSyntaxProvider(
								predicate: (sn, _) => FindCorrectComment(sn),
								transform: (ctx, _) => GetDataForGeneration(ctx)
							)
							.Where(it => it != null)
							.SelectMany((it, _) => it!)
							;
						

Class2Dictionary, https://www.nuget.org/packages/RSCG_Templating


[IGenerateDataFromClass("ClassPropByName")]
public partial class Person
{
	public string? FirstName { get; set; }
	public string? LastName { get; set; }
}

var p = new Person();
p.FirstName = "Andrei";
//set last name via prop
p.SetPropValue(ePerson_Properties.LastName, "Ignat");
Console.WriteLine("called directly last name : " 
+ p.LastName);
//get last name via enum
Console.WriteLine("called via enum : "
		+ p.GetPropValue(ePerson_Properties.FirstName));

private bool IsSyntaxTargetForGeneration(SyntaxNode s)
{
	if(s is not ClassDeclarationSyntax cds) return false;
	if(cds.AttributeLists.Count == 0) return false;
	return cds.AttributeLists.Any(it => it.ToFullString()
		.Trim().Contains("IGenerateDataFromClass"));
	
}											
var methods = symbolClass
    .GetMembers()
    .Where(it=>it.Kind == SymbolKind.Method)
    .Select(it=>it as IMethodSymbol)
    .Where(it=>it != null)
    .Select(it=>it!)
            
If you want to study ,there are at https://github.com/search?q=repo%3Adotnet%2Fruntime%20IIncrementalGenerator&type=code

System.Text.Json,System.Text.RegularExpressions,

Microsoft.Extensions.Logging,Microsoft.Extensions.Options.Generators.OptionsValidatorGenerator,

Microsoft.Extensions.Configuration.Binder,RDG,Com,TelemetryLogging

You can see examples at https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG#12-created-by-microsoft


See https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation?pivots=dotnet-8-0
Demo SerializerBench

Questions ?

Thank you for your time
https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG
Andrei Ignat http://msprogrammer.serviciipeweb.ro/