in src/CodeGenerators/SettingsGen/SettingsGenerator.cs [34:72]
protected override bool ShouldGenerateFile(GeneratorExecutionContext context, out AdditionalText? settingsFile)
{
try
{
// Load settings from file provided via property in csproj
if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.GenerateSettingsFile", out string? value) &&
bool.TryParse(value ?? string.Empty, out bool shouldGen))
{
if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.SettingsFile", out value))
{
settingsFile = new SettingsAdditionalText(value);
}
else
{
settingsFile = null;
}
return shouldGen;
}
// Load settings from additional files
foreach (AdditionalText file in context.AdditionalFiles)
{
if (string.Equals(Path.GetFileName(file.Path), Filename, StringComparison.OrdinalIgnoreCase))
{
settingsFile = file;
return ShouldGen(context, file);
}
}
settingsFile = null;
return false;
}
catch (Exception ex)
{
context.ReportDiagnostic(Diagnostic.Create(EncounteredError, null, ex.Message));
throw;
}
}