public void Execute(GeneratorExecutionContext context) { try { context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.NamespaceName", out var globalNamespaceName); var files = context.AdditionalFiles.Where(at => at.Path.EndsWith(".svg", StringComparison.InvariantCultureIgnoreCase)); foreach (var file in files) { string?namespaceName = null; if (!string.IsNullOrWhiteSpace(globalNamespaceName)) { namespaceName = globalNamespaceName; } if (context.AnalyzerConfigOptions.GetOptions(file).TryGetValue("build_metadata.AdditionalFiles.NamespaceName", out var perFilenamespaceName)) { if (!string.IsNullOrWhiteSpace(perFilenamespaceName)) { namespaceName = perFilenamespaceName; } } if (string.IsNullOrWhiteSpace(namespaceName)) { namespaceName = "Svg"; } context.AnalyzerConfigOptions.GetOptions(file).TryGetValue("build_metadata.AdditionalFiles.ClassName", out var className); if (string.IsNullOrWhiteSpace(className)) { className = CreateClassName(file.Path); } if (string.IsNullOrWhiteSpace(namespaceName)) { context.ReportDiagnostic(Diagnostic.Create(s_errorDescriptor, Location.None, "The specified namespace name is invalid.")); return; } if (string.IsNullOrWhiteSpace(className)) { context.ReportDiagnostic(Diagnostic.Create(s_errorDescriptor, Location.None, "The specified class name is invalid.")); return; } var svg = file.GetText(context.CancellationToken)?.ToString(); if (string.IsNullOrWhiteSpace(svg)) { context.ReportDiagnostic(Diagnostic.Create(s_errorDescriptor, Location.None, "Svg file is null or empty.")); return; } var svgDocument = SvgExtensions.FromSvg(svg !); if (svgDocument is { }) { var picture = SvgExtensions.ToModel(svgDocument, _assetLoader, out _, out _); if (picture is { } && picture.Commands is { })