System.Console.WriteLine("Ignat Andrei");
System.Console.WriteLine("RoslynAndInterceptors");
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
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!)
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