I'm trying to build my first source generator, the source generator is designed to register hangfire recurring jobs and a basic version is working similar to the. You can see this on the master branch in this project
Idea is, you'll be able to add an attribute too the recurring job class -
[RecurringJob("DeleteOldReportsAtMidnight", "* *678 * *")]
public class DeleteOldReports
{
public void Execute()
{
}
}
The source generator automatically generates -
namespace TestSolution;
// <auto-generated/>
using Hangfire;
using Microsoft.Extensions.DependencyInjection;
public static class ServiceRegistrationExtensions
{
public static IServiceCollection RegisterServicesFromTestSolution(this IServiceCollection sc)
{
RecurringJob.AddOrUpdate<TestSolution.DeleteOldReports>("DeleteOldReportsAtMidnight", x => x.Execute(), "* *678 * *");
return sc;
}
}
And all the user has too do is call the registration method at start up
ServiceRegistrationExtensions.RegisterServicesFromTestSolution(services)
The bit im struggling with now is using more advanced attribute with optional parameters. You can see my desired attribute here on a different branch
Im able to get the attributes on the class but the NamedArguments
is always empty
It's been some time since i did SG's, but i think the problem is, that you're not actually using named arguments, wich should look like this:
[RecurringJob(action: "DeleteOldReportsAtMidnight", pattern: "* *678 * *")]
The names of the parameters of the constructer are irrelevant here, if i remember correctly. You can even use the semantic and or syntax model there, to generate the matching constructor for given parameters and feed dynamic information into your SG.