| | | 1 | | using Microsoft.CodeAnalysis; |
| | | 2 | | using Microsoft.CodeAnalysis.Text; |
| | | 3 | | using NexusLabs.Needlr.Generators.Helpers; |
| | | 4 | | using NexusLabs.Needlr.Generators.Models; |
| | | 5 | | using System.Text; |
| | | 6 | | |
| | | 7 | | namespace NexusLabs.Needlr.Generators; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Incremental source generator that produces a compile-time type registry |
| | | 11 | | /// for dependency injection, eliminating runtime reflection. |
| | | 12 | | /// </summary> |
| | | 13 | | [Generator(LanguageNames.CSharp)] |
| | | 14 | | public sealed class TypeRegistryGenerator : IIncrementalGenerator |
| | | 15 | | { |
| | | 16 | | private const string GenerateTypeRegistryAttributeName = "NexusLabs.Needlr.Generators.GenerateTypeRegistryAttribute" |
| | | 17 | | |
| | | 18 | | public void Initialize(IncrementalGeneratorInitializationContext context) |
| | | 19 | | { |
| | | 20 | | // Combine compilation with analyzer config options to read MSBuild properties |
| | 609 | 21 | | var compilationAndOptions = context.CompilationProvider |
| | 609 | 22 | | .Combine(context.AnalyzerConfigOptionsProvider); |
| | | 23 | | |
| | | 24 | | // ForAttributeWithMetadataName doesn't work for assembly-level attributes. |
| | | 25 | | // Instead, we register directly on the compilation provider and check |
| | | 26 | | // compilation.Assembly.GetAttributes() for [GenerateTypeRegistry]. |
| | 609 | 27 | | context.RegisterSourceOutput(compilationAndOptions, static (spc, source) => |
| | 609 | 28 | | { |
| | 609 | 29 | | var (compilation, configOptions) = source; |
| | 609 | 30 | | |
| | 609 | 31 | | var attributeInfo = GetAttributeInfoFromCompilation(compilation); |
| | 609 | 32 | | if (attributeInfo == null) |
| | 1 | 33 | | return; |
| | 609 | 34 | | |
| | 608 | 35 | | var info = attributeInfo.Value; |
| | 608 | 36 | | var assemblyName = compilation.AssemblyName ?? "Generated"; |
| | 609 | 37 | | |
| | 609 | 38 | | // Read breadcrumb level from MSBuild property |
| | 608 | 39 | | var breadcrumbLevel = GetBreadcrumbLevel(configOptions); |
| | 608 | 40 | | var projectDirectory = GetProjectDirectory(configOptions); |
| | 608 | 41 | | var breadcrumbs = new BreadcrumbWriter(breadcrumbLevel); |
| | 609 | 42 | | |
| | 609 | 43 | | // Check if this is an AOT project |
| | 608 | 44 | | var isAotProject = IsAotProject(configOptions); |
| | 609 | 45 | | |
| | 608 | 46 | | var discoveryResult = DiscoverTypes( |
| | 608 | 47 | | compilation, |
| | 608 | 48 | | info.NamespacePrefixes, |
| | 608 | 49 | | info.ExcludeNamespacePrefixes, |
| | 608 | 50 | | info.IncludeSelf); |
| | 609 | 51 | | |
| | 608 | 52 | | var boundCompilation = FactoryConsumerDiscoveryHelper.BindFactoryConsumers( |
| | 608 | 53 | | compilation, |
| | 608 | 54 | | discoveryResult.Factories, |
| | 608 | 55 | | assemblyName, |
| | 608 | 56 | | breadcrumbs, |
| | 608 | 57 | | projectDirectory); |
| | 608 | 58 | | if (!ReferenceEquals(boundCompilation, compilation)) |
| | 609 | 59 | | { |
| | 43 | 60 | | discoveryResult = DiscoverTypes( |
| | 43 | 61 | | boundCompilation, |
| | 43 | 62 | | info.NamespacePrefixes, |
| | 43 | 63 | | info.ExcludeNamespacePrefixes, |
| | 43 | 64 | | info.IncludeSelf); |
| | 609 | 65 | | } |
| | 609 | 66 | | |
| | 609 | 67 | | // Discover referenced assemblies with [GenerateTypeRegistry] for forced loading. |
| | 609 | 68 | | // Done early so the empty-result check below can include this in its decision. |
| | 609 | 69 | | // Note: Order of force-loading doesn't matter; ordering is applied at service registration time |
| | 608 | 70 | | var referencedAssemblies = AssemblyDiscoveryHelper.DiscoverReferencedAssembliesWithTypeRegistry(compilation) |
| | 2 | 71 | | .OrderBy(a => a, StringComparer.OrdinalIgnoreCase) |
| | 608 | 72 | | .ToList(); |
| | 609 | 73 | | |
| | 609 | 74 | | // Nothing was discovered: no injectable types, factories, providers, options, |
| | 609 | 75 | | // interceptors, hosted services, plugins, no referenced assemblies to force-load, |
| | 609 | 76 | | // no inaccessible type errors, and no missing TypeRegistry warnings. |
| | 608 | 77 | | var nothingDiscovered = |
| | 608 | 78 | | discoveryResult.InjectableTypes.Count == 0 && |
| | 608 | 79 | | discoveryResult.PluginTypes.Count == 0 && |
| | 608 | 80 | | discoveryResult.Decorators.Count == 0 && |
| | 608 | 81 | | discoveryResult.InterceptedServices.Count == 0 && |
| | 608 | 82 | | discoveryResult.Factories.Count == 0 && |
| | 608 | 83 | | discoveryResult.Options.Count == 0 && |
| | 608 | 84 | | discoveryResult.HttpClients.Count == 0 && |
| | 608 | 85 | | discoveryResult.HostedServices.Count == 0 && |
| | 608 | 86 | | discoveryResult.Providers.Count == 0 && |
| | 608 | 87 | | discoveryResult.ComposedRegistrations.Count == 0 && |
| | 608 | 88 | | discoveryResult.InaccessibleTypes.Count == 0 && |
| | 608 | 89 | | discoveryResult.MissingTypeRegistryPlugins.Count == 0 && |
| | 608 | 90 | | referencedAssemblies.Count == 0; |
| | 609 | 91 | | |
| | 608 | 92 | | var registrationPlan = GeneratedRegistrationPlanBuilder.Create( |
| | 608 | 93 | | assemblyName, |
| | 608 | 94 | | isAotProject, |
| | 608 | 95 | | registersServiceCatalog: !nothingDiscovered, |
| | 608 | 96 | | referencedAssemblies, |
| | 608 | 97 | | discoveryResult); |
| | 608 | 98 | | if (ShouldEmitRegistrationManifest(configOptions)) |
| | 609 | 99 | | { |
| | 18 | 100 | | var registrationManifestSource = |
| | 18 | 101 | | CodeGen.RegistrationManifestCodeGenerator.GenerateSource( |
| | 18 | 102 | | registrationPlan, |
| | 18 | 103 | | breadcrumbs); |
| | 18 | 104 | | spc.AddSource( |
| | 18 | 105 | | "NeedlrRegistrationManifest.g.cs", |
| | 18 | 106 | | GeneratedSourceText.Create(registrationManifestSource)); |
| | 609 | 107 | | } |
| | 609 | 108 | | |
| | 609 | 109 | | // A type-less assembly that still carries [GenerateTypeRegistry] (guaranteed here by the |
| | 609 | 110 | | // attributeInfo guard above) is a declared Needlr participant. Consumers force-load |
| | 609 | 111 | | // typeof({Assembly}.Generated.TypeRegistry) for every attribute-carrying referenced |
| | 609 | 112 | | // assembly, so emitting nothing makes those consumers fail to compile with CS0234. Emit |
| | 609 | 113 | | // a minimal registry instead. It depends only on the attributes package (never the |
| | 609 | 114 | | // injection packages), so it compiles whether or not this assembly references them — a |
| | 609 | 115 | | // domain, contracts, or documentation-only project participates without being forced to |
| | 609 | 116 | | // take a dependency it would not otherwise have. |
| | 608 | 117 | | if (nothingDiscovered) |
| | 609 | 118 | | { |
| | 11 | 119 | | var emptyRegistrySource = |
| | 11 | 120 | | CodeGen.EmptyTypeRegistryCodeGenerator.GenerateTypeRegistrySource( |
| | 11 | 121 | | registrationPlan, |
| | 11 | 122 | | breadcrumbs); |
| | 11 | 123 | | spc.AddSource("TypeRegistry.g.cs", GeneratedSourceText.Create(emptyRegistrySource)); |
| | 609 | 124 | | |
| | 11 | 125 | | var emptyBootstrapSource = |
| | 11 | 126 | | CodeGen.EmptyTypeRegistryCodeGenerator.GenerateBootstrapSource( |
| | 11 | 127 | | registrationPlan, |
| | 11 | 128 | | breadcrumbs); |
| | 11 | 129 | | spc.AddSource("NeedlrSourceGenBootstrap.g.cs", GeneratedSourceText.Create(emptyBootstrapSource)); |
| | 11 | 130 | | return; |
| | 609 | 131 | | } |
| | 609 | 132 | | |
| | 609 | 133 | | // Report errors for inaccessible internal types in referenced assemblies |
| | 6468 | 134 | | foreach (var inaccessibleType in discoveryResult.InaccessibleTypes) |
| | 609 | 135 | | { |
| | 2637 | 136 | | spc.ReportDiagnostic(Diagnostic.Create( |
| | 2637 | 137 | | DiagnosticDescriptors.InaccessibleInternalType, |
| | 2637 | 138 | | Location.None, |
| | 2637 | 139 | | inaccessibleType.TypeName, |
| | 2637 | 140 | | inaccessibleType.AssemblyName)); |
| | 609 | 141 | | } |
| | 609 | 142 | | |
| | 609 | 143 | | // Report errors for referenced assemblies with internal plugin types but no [GenerateTypeRegistry] |
| | 1196 | 144 | | foreach (var missingPlugin in discoveryResult.MissingTypeRegistryPlugins) |
| | 609 | 145 | | { |
| | 1 | 146 | | spc.ReportDiagnostic(Diagnostic.Create( |
| | 1 | 147 | | DiagnosticDescriptors.MissingGenerateTypeRegistryAttribute, |
| | 1 | 148 | | Location.None, |
| | 1 | 149 | | missingPlugin.AssemblyName, |
| | 1 | 150 | | missingPlugin.TypeName)); |
| | 609 | 151 | | } |
| | 609 | 152 | | |
| | 609 | 153 | | // NDLRGEN020: Previously reported error if [Options] used in AOT project |
| | 609 | 154 | | // Now removed for parity - we generate best-effort code and let unsupported |
| | 609 | 155 | | // types fail at runtime (matching non-AOT ConfigurationBinder behavior) |
| | 609 | 156 | | |
| | 609 | 157 | | // NDLRGEN021: Report warning for non-partial positional records |
| | 1374 | 158 | | foreach (var opt in discoveryResult.Options.Where(o => o.IsNonPartialPositionalRecord)) |
| | 609 | 159 | | { |
| | 2 | 160 | | spc.ReportDiagnostic(Diagnostic.Create( |
| | 2 | 161 | | DiagnosticDescriptors.PositionalRecordMustBePartial, |
| | 2 | 162 | | Location.None, |
| | 2 | 163 | | opt.TypeName)); |
| | 609 | 164 | | } |
| | 609 | 165 | | |
| | 609 | 166 | | // NDLRGEN022: Detect disposable captive dependencies using inferred lifetimes |
| | 597 | 167 | | CaptiveDependencyAnalyzer.ReportDisposableCaptiveDependencies(spc, discoveryResult); |
| | 609 | 168 | | |
| | 609 | 169 | | // NDLRGEN038: Report skipped composition registrations whose discovered type argument(s) |
| | 609 | 170 | | // violate the composition's generic constraints. |
| | 1262 | 171 | | foreach (var violation in discoveryResult.ComposedConstraintViolations) |
| | 609 | 172 | | { |
| | 34 | 173 | | spc.ReportDiagnostic(Diagnostic.Create( |
| | 34 | 174 | | DiagnosticDescriptors.ComposedTypeArgumentViolatesConstraints, |
| | 34 | 175 | | Location.None, |
| | 34 | 176 | | violation.CompositionTypeName, |
| | 34 | 177 | | violation.TypeArgumentName, |
| | 34 | 178 | | violation.SourceInterfaceName)); |
| | 609 | 179 | | } |
| | 609 | 180 | | |
| | 597 | 181 | | var sourceText = GenerateTypeRegistrySource( |
| | 597 | 182 | | registrationPlan, |
| | 597 | 183 | | breadcrumbs, |
| | 597 | 184 | | projectDirectory); |
| | 597 | 185 | | spc.AddSource("TypeRegistry.g.cs", GeneratedSourceText.Create(sourceText)); |
| | 609 | 186 | | |
| | 597 | 187 | | var bootstrapText = CodeGen.BootstrapCodeGenerator.GenerateModuleInitializerBootstrapSource( |
| | 597 | 188 | | registrationPlan.AssemblyName, |
| | 597 | 189 | | registrationPlan.ReferencedRegistryAssemblies, |
| | 597 | 190 | | breadcrumbs, |
| | 597 | 191 | | registrationPlan.HasFactoryRegistrations, |
| | 597 | 192 | | registrationPlan.HasConfigBoundRegistrations, |
| | 597 | 193 | | registrationPlan.HasProviderRegistrations); |
| | 597 | 194 | | spc.AddSource("NeedlrSourceGenBootstrap.g.cs", GeneratedSourceText.Create(bootstrapText)); |
| | 609 | 195 | | |
| | 609 | 196 | | // Generate interceptor proxy classes if any were discovered |
| | 597 | 197 | | if (registrationPlan.DiscoveryResult.InterceptedServices.Count > 0) |
| | 609 | 198 | | { |
| | 15 | 199 | | var interceptorProxiesText = CodeGen.InterceptorCodeGenerator.GenerateInterceptorProxiesSource( |
| | 15 | 200 | | registrationPlan.DiscoveryResult.InterceptedServices, |
| | 15 | 201 | | registrationPlan.AssemblyName, |
| | 15 | 202 | | breadcrumbs, |
| | 15 | 203 | | projectDirectory); |
| | 15 | 204 | | spc.AddSource("InterceptorProxies.g.cs", GeneratedSourceText.Create(interceptorProxiesText)); |
| | 609 | 205 | | } |
| | 609 | 206 | | |
| | 609 | 207 | | // Generate factory classes if any were discovered |
| | 597 | 208 | | if (registrationPlan.HasFactoryRegistrations) |
| | 609 | 209 | | { |
| | 45 | 210 | | var factoriesText = CodeGen.FactoryCodeGenerator.GenerateFactoriesSource( |
| | 45 | 211 | | registrationPlan.EmittedFactories, |
| | 45 | 212 | | registrationPlan.AssemblyName, |
| | 45 | 213 | | breadcrumbs, |
| | 45 | 214 | | projectDirectory); |
| | 45 | 215 | | spc.AddSource("Factories.g.cs", GeneratedSourceText.Create(factoriesText)); |
| | 609 | 216 | | } |
| | 609 | 217 | | |
| | 609 | 218 | | // Generate provider classes if any were discovered |
| | 597 | 219 | | if (registrationPlan.HasProviderRegistrations) |
| | 609 | 220 | | { |
| | 609 | 221 | | // Interface-based providers go in the Generated namespace |
| | 18 | 222 | | var interfaceProviders = registrationPlan.EmittedProviders |
| | 19 | 223 | | .Where(p => p.IsInterface) |
| | 18 | 224 | | .ToList(); |
| | 18 | 225 | | if (interfaceProviders.Count > 0) |
| | 609 | 226 | | { |
| | 12 | 227 | | var providersText = CodeGen.ProviderCodeGenerator.GenerateProvidersSource( |
| | 12 | 228 | | interfaceProviders, |
| | 12 | 229 | | registrationPlan.AssemblyName, |
| | 12 | 230 | | breadcrumbs, |
| | 12 | 231 | | projectDirectory); |
| | 12 | 232 | | spc.AddSource("Providers.g.cs", GeneratedSourceText.Create(providersText)); |
| | 609 | 233 | | } |
| | 609 | 234 | | |
| | 609 | 235 | | // Shorthand class providers need to be generated in their original namespace |
| | 18 | 236 | | var classProviders = registrationPlan.EmittedProviders |
| | 19 | 237 | | .Where(p => !p.IsInterface && p.IsPartial) |
| | 18 | 238 | | .ToList(); |
| | 48 | 239 | | foreach (var provider in classProviders) |
| | 609 | 240 | | { |
| | 6 | 241 | | var providerText = CodeGen.ProviderCodeGenerator.GenerateShorthandProviderSource( |
| | 6 | 242 | | provider, |
| | 6 | 243 | | registrationPlan.AssemblyName, |
| | 6 | 244 | | breadcrumbs, |
| | 6 | 245 | | projectDirectory); |
| | 6 | 246 | | spc.AddSource($"Provider.{provider.SimpleTypeName}.g.cs", GeneratedSourceText.Create(providerText)); |
| | 609 | 247 | | } |
| | 609 | 248 | | } |
| | 609 | 249 | | |
| | 609 | 250 | | // Generate options validator classes if any have validation methods |
| | 597 | 251 | | var optionsWithValidators = registrationPlan.DiscoveryResult.Options |
| | 176 | 252 | | .Where(o => o.HasValidatorMethod) |
| | 597 | 253 | | .ToList(); |
| | 597 | 254 | | if (optionsWithValidators.Count > 0) |
| | 609 | 255 | | { |
| | 22 | 256 | | var validatorsText = CodeGen.OptionsCodeGenerator.GenerateOptionsValidatorsSource( |
| | 22 | 257 | | optionsWithValidators, |
| | 22 | 258 | | registrationPlan.AssemblyName, |
| | 22 | 259 | | breadcrumbs, |
| | 22 | 260 | | projectDirectory); |
| | 22 | 261 | | spc.AddSource("OptionsValidators.g.cs", GeneratedSourceText.Create(validatorsText)); |
| | 609 | 262 | | } |
| | 609 | 263 | | |
| | 609 | 264 | | // Generate DataAnnotations validator classes if any have DataAnnotation attributes |
| | 597 | 265 | | var optionsWithDataAnnotations = registrationPlan.DiscoveryResult.Options |
| | 176 | 266 | | .Where(o => o.HasDataAnnotations) |
| | 597 | 267 | | .ToList(); |
| | 597 | 268 | | if (optionsWithDataAnnotations.Count > 0) |
| | 609 | 269 | | { |
| | 19 | 270 | | var dataAnnotationsValidatorsText = CodeGen.OptionsCodeGenerator.GenerateDataAnnotationsValidatorsSource |
| | 19 | 271 | | optionsWithDataAnnotations, |
| | 19 | 272 | | registrationPlan.AssemblyName, |
| | 19 | 273 | | breadcrumbs, |
| | 19 | 274 | | projectDirectory); |
| | 19 | 275 | | spc.AddSource("OptionsDataAnnotationsValidators.g.cs", GeneratedSourceText.Create(dataAnnotationsValidat |
| | 609 | 276 | | } |
| | 609 | 277 | | |
| | 609 | 278 | | // Generate parameterless constructors for partial positional records with [Options] |
| | 597 | 279 | | var optionsNeedingConstructors = registrationPlan.DiscoveryResult.Options |
| | 176 | 280 | | .Where(o => o.NeedsGeneratedConstructor) |
| | 597 | 281 | | .ToList(); |
| | 597 | 282 | | if (optionsNeedingConstructors.Count > 0) |
| | 609 | 283 | | { |
| | 12 | 284 | | var constructorsText = CodeGen.OptionsCodeGenerator.GeneratePositionalRecordConstructorsSource( |
| | 12 | 285 | | optionsNeedingConstructors, |
| | 12 | 286 | | registrationPlan.AssemblyName, |
| | 12 | 287 | | breadcrumbs, |
| | 12 | 288 | | projectDirectory); |
| | 12 | 289 | | spc.AddSource("OptionsConstructors.g.cs", GeneratedSourceText.Create(constructorsText)); |
| | 609 | 290 | | } |
| | 609 | 291 | | |
| | 609 | 292 | | // Generate ServiceCatalog for runtime introspection |
| | 597 | 293 | | var catalogText = CodeGen.ServiceCatalogCodeGenerator.GenerateServiceCatalogSource( |
| | 597 | 294 | | registrationPlan, |
| | 597 | 295 | | projectDirectory, |
| | 597 | 296 | | breadcrumbs); |
| | 597 | 297 | | spc.AddSource("ServiceCatalog.g.cs", GeneratedSourceText.Create(catalogText)); |
| | 609 | 298 | | |
| | 609 | 299 | | // Generate diagnostic output files if configured |
| | 597 | 300 | | var diagnosticOptions = GetDiagnosticOptions(configOptions); |
| | 597 | 301 | | if (diagnosticOptions.Enabled) |
| | 609 | 302 | | { |
| | 109 | 303 | | var referencedAssemblyTypes = AssemblyDiscoveryHelper.DiscoverReferencedAssemblyTypesForDiagnostics(comp |
| | 109 | 304 | | var diagnosticsText = DiagnosticsGenerator.GenerateDiagnosticsSource(discoveryResult, assemblyName, proj |
| | 109 | 305 | | spc.AddSource("NeedlrDiagnostics.g.cs", GeneratedSourceText.Create(diagnosticsText)); |
| | 609 | 306 | | } |
| | 609 | 307 | | |
| | 609 | 308 | | // Generate IDE graph export if configured |
| | 597 | 309 | | if (ShouldExportGraph(configOptions)) |
| | 609 | 310 | | { |
| | 609 | 311 | | // Discover types from referenced assemblies with [GenerateTypeRegistry] for graph inclusion |
| | 19 | 312 | | var referencedAssemblyTypesForGraph = AssemblyDiscoveryHelper.DiscoverReferencedAssemblyTypesForGraph(co |
| | 609 | 313 | | |
| | 19 | 314 | | var graphJson = Export.GraphExporter.GenerateGraphJson( |
| | 19 | 315 | | discoveryResult, |
| | 19 | 316 | | assemblyName, |
| | 19 | 317 | | projectDirectory, |
| | 19 | 318 | | diagnostics: null, |
| | 19 | 319 | | referencedAssemblyTypes: referencedAssemblyTypesForGraph); |
| | 609 | 320 | | |
| | 609 | 321 | | // Embed graph as a comment in a generated file so it's accessible |
| | 609 | 322 | | // The actual JSON is written to obj folder via the generated code |
| | 19 | 323 | | var graphSourceText = Export.GraphExporter.GenerateGraphExportSource(graphJson, assemblyName, breadcrumb |
| | 19 | 324 | | spc.AddSource("NeedlrGraph.g.cs", GeneratedSourceText.Create(graphSourceText)); |
| | 609 | 325 | | } |
| | 1206 | 326 | | }); |
| | 609 | 327 | | } |
| | | 328 | | |
| | | 329 | | internal static BreadcrumbLevel GetBreadcrumbLevel(Microsoft.CodeAnalysis.Diagnostics.AnalyzerConfigOptionsProvider |
| | | 330 | | { |
| | 723 | 331 | | if (configOptions.GlobalOptions.TryGetValue("build_property.NeedlrBreadcrumbLevel", out var levelStr) && |
| | 723 | 332 | | !string.IsNullOrWhiteSpace(levelStr)) |
| | | 333 | | { |
| | 259 | 334 | | if (levelStr.Equals("None", StringComparison.OrdinalIgnoreCase)) |
| | 17 | 335 | | return BreadcrumbLevel.None; |
| | 242 | 336 | | if (levelStr.Equals("Verbose", StringComparison.OrdinalIgnoreCase)) |
| | 28 | 337 | | return BreadcrumbLevel.Verbose; |
| | | 338 | | } |
| | | 339 | | |
| | | 340 | | // Default to Minimal |
| | 678 | 341 | | return BreadcrumbLevel.Minimal; |
| | | 342 | | } |
| | | 343 | | |
| | | 344 | | private static string? GetProjectDirectory(Microsoft.CodeAnalysis.Diagnostics.AnalyzerConfigOptionsProvider configOp |
| | | 345 | | { |
| | | 346 | | // Try to get the project directory from MSBuild properties |
| | 608 | 347 | | if (configOptions.GlobalOptions.TryGetValue("build_property.ProjectDir", out var projectDir) && |
| | 608 | 348 | | !string.IsNullOrWhiteSpace(projectDir)) |
| | | 349 | | { |
| | 4 | 350 | | return projectDir.TrimEnd('/', '\\'); |
| | | 351 | | } |
| | | 352 | | |
| | 604 | 353 | | return null; |
| | | 354 | | } |
| | | 355 | | |
| | | 356 | | private static DiagnosticOptions GetDiagnosticOptions(Microsoft.CodeAnalysis.Diagnostics.AnalyzerConfigOptionsProvid |
| | | 357 | | { |
| | 597 | 358 | | configOptions.GlobalOptions.TryGetValue("build_property.NeedlrDiagnostics", out var enabled); |
| | 597 | 359 | | configOptions.GlobalOptions.TryGetValue("build_property.NeedlrDiagnosticsPath", out var outputPath); |
| | 597 | 360 | | configOptions.GlobalOptions.TryGetValue("build_property.NeedlrDiagnosticsFilter", out var filter); |
| | | 361 | | |
| | 597 | 362 | | return DiagnosticOptions.Parse(enabled, outputPath, filter); |
| | | 363 | | } |
| | | 364 | | |
| | | 365 | | /// <summary> |
| | | 366 | | /// Checks if the IDE graph export is enabled. |
| | | 367 | | /// </summary> |
| | | 368 | | private static bool ShouldExportGraph(Microsoft.CodeAnalysis.Diagnostics.AnalyzerConfigOptionsProvider configOptions |
| | | 369 | | { |
| | | 370 | | // Export graph is disabled by default |
| | | 371 | | // Enable with NeedlrExportGraph=true in project file |
| | 597 | 372 | | if (configOptions.GlobalOptions.TryGetValue("build_property.NeedlrExportGraph", out var exportGraph) && |
| | 597 | 373 | | exportGraph.Equals("true", StringComparison.OrdinalIgnoreCase)) |
| | | 374 | | { |
| | 19 | 375 | | return true; |
| | | 376 | | } |
| | 578 | 377 | | return false; |
| | | 378 | | } |
| | | 379 | | |
| | | 380 | | private static bool ShouldEmitRegistrationManifest( |
| | | 381 | | Microsoft.CodeAnalysis.Diagnostics.AnalyzerConfigOptionsProvider configOptions) |
| | | 382 | | { |
| | 608 | 383 | | return configOptions.GlobalOptions.TryGetValue( |
| | 608 | 384 | | "build_property.NeedlrEmitRegistrationManifest", |
| | 608 | 385 | | out var enabled) && |
| | 608 | 386 | | enabled.Equals( |
| | 608 | 387 | | "true", |
| | 608 | 388 | | StringComparison.OrdinalIgnoreCase); |
| | | 389 | | } |
| | | 390 | | |
| | | 391 | | /// <summary> |
| | | 392 | | /// Checks if the project is configured for AOT compilation. |
| | | 393 | | /// Returns true if either PublishAot or IsAotCompatible is set to true. |
| | | 394 | | /// </summary> |
| | | 395 | | private static bool IsAotProject(Microsoft.CodeAnalysis.Diagnostics.AnalyzerConfigOptionsProvider configOptions) |
| | | 396 | | { |
| | 608 | 397 | | if (configOptions.GlobalOptions.TryGetValue("build_property.PublishAot", out var publishAot) && |
| | 608 | 398 | | publishAot.Equals("true", StringComparison.OrdinalIgnoreCase)) |
| | | 399 | | { |
| | 86 | 400 | | return true; |
| | | 401 | | } |
| | | 402 | | |
| | 522 | 403 | | if (configOptions.GlobalOptions.TryGetValue("build_property.IsAotCompatible", out var isAotCompatible) && |
| | 522 | 404 | | isAotCompatible.Equals("true", StringComparison.OrdinalIgnoreCase)) |
| | | 405 | | { |
| | 1 | 406 | | return true; |
| | | 407 | | } |
| | | 408 | | |
| | 521 | 409 | | return false; |
| | | 410 | | } |
| | | 411 | | |
| | | 412 | | private static AttributeInfo? GetAttributeInfoFromCompilation(Compilation compilation) |
| | | 413 | | { |
| | | 414 | | // Get assembly-level attributes directly from the compilation |
| | 1826 | 415 | | foreach (var attribute in compilation.Assembly.GetAttributes()) |
| | | 416 | | { |
| | 608 | 417 | | var attrClassName = attribute.AttributeClass?.ToDisplayString(); |
| | | 418 | | |
| | | 419 | | // Check if this is our attribute (various name format possibilities) |
| | 608 | 420 | | if (attrClassName != GenerateTypeRegistryAttributeName) |
| | | 421 | | continue; |
| | | 422 | | |
| | 608 | 423 | | string[]? namespacePrefixes = null; |
| | 608 | 424 | | string[]? excludeNamespacePrefixes = null; |
| | 608 | 425 | | var includeSelf = true; |
| | | 426 | | |
| | 1578 | 427 | | foreach (var namedArg in attribute.NamedArguments) |
| | | 428 | | { |
| | 181 | 429 | | switch (namedArg.Key) |
| | | 430 | | { |
| | | 431 | | case "IncludeNamespacePrefixes": |
| | 169 | 432 | | if (!namedArg.Value.IsNull && namedArg.Value.Values.Length > 0) |
| | | 433 | | { |
| | 169 | 434 | | namespacePrefixes = namedArg.Value.Values |
| | 171 | 435 | | .Where(v => v.Value is string) |
| | 171 | 436 | | .Select(v => (string)v.Value!) |
| | 169 | 437 | | .ToArray(); |
| | | 438 | | } |
| | 169 | 439 | | break; |
| | | 440 | | |
| | | 441 | | case "ExcludeNamespacePrefixes": |
| | 1 | 442 | | if (!namedArg.Value.IsNull && namedArg.Value.Values.Length > 0) |
| | | 443 | | { |
| | 1 | 444 | | excludeNamespacePrefixes = namedArg.Value.Values |
| | 1 | 445 | | .Where(v => v.Value is string) |
| | 1 | 446 | | .Select(v => (string)v.Value!) |
| | 1 | 447 | | .ToArray(); |
| | | 448 | | } |
| | 1 | 449 | | break; |
| | | 450 | | |
| | | 451 | | case "IncludeSelf": |
| | 11 | 452 | | if (namedArg.Value.Value is bool selfValue) |
| | | 453 | | { |
| | 11 | 454 | | includeSelf = selfValue; |
| | | 455 | | } |
| | | 456 | | break; |
| | | 457 | | } |
| | | 458 | | } |
| | | 459 | | |
| | 608 | 460 | | return new AttributeInfo(namespacePrefixes, excludeNamespacePrefixes, includeSelf); |
| | | 461 | | } |
| | | 462 | | |
| | 1 | 463 | | return null; |
| | | 464 | | } |
| | | 465 | | |
| | | 466 | | private static DiscoveryResult DiscoverTypes( |
| | | 467 | | Compilation compilation, |
| | | 468 | | string[]? namespacePrefixes, |
| | | 469 | | string[]? excludeNamespacePrefixes, |
| | | 470 | | bool includeSelf) |
| | | 471 | | { |
| | 651 | 472 | | var injectableTypes = new List<DiscoveredType>(); |
| | 651 | 473 | | var pluginTypes = new List<DiscoveredPlugin>(); |
| | 651 | 474 | | var decorators = new List<DiscoveredDecorator>(); |
| | 651 | 475 | | var openDecorators = new List<DiscoveredOpenDecorator>(); |
| | 651 | 476 | | var composedMarkers = new List<DiscoveredComposedMarker>(); |
| | 651 | 477 | | var composedCandidateTypes = new List<INamedTypeSymbol>(); |
| | 651 | 478 | | var interceptedServices = new List<DiscoveredInterceptedService>(); |
| | 651 | 479 | | var factories = new List<DiscoveredFactory>(); |
| | 651 | 480 | | var options = new List<DiscoveredOptions>(); |
| | 651 | 481 | | var hostedServices = new List<DiscoveredHostedService>(); |
| | 651 | 482 | | var providers = new List<DiscoveredProvider>(); |
| | 651 | 483 | | var httpClients = new List<DiscoveredHttpClient>(); |
| | 651 | 484 | | var inaccessibleTypes = new List<InaccessibleType>(); |
| | 651 | 485 | | var prefixList = namespacePrefixes?.ToList(); |
| | 651 | 486 | | var excludePrefixList = excludeNamespacePrefixes?.ToList(); |
| | | 487 | | |
| | | 488 | | // Compute the generated namespace for the current assembly |
| | 651 | 489 | | var currentAssemblyName = compilation.Assembly.Name; |
| | 651 | 490 | | var safeAssemblyName = GeneratorHelpers.SanitizeIdentifier(currentAssemblyName); |
| | 651 | 491 | | var generatedNamespace = $"{safeAssemblyName}.Generated"; |
| | | 492 | | |
| | | 493 | | // Collect types from the current compilation if includeSelf is true |
| | 651 | 494 | | if (includeSelf) |
| | | 495 | | { |
| | 649 | 496 | | CollectTypesFromAssembly(compilation.Assembly, prefixList, excludePrefixList, injectableTypes, pluginTypes, |
| | | 497 | | } |
| | | 498 | | |
| | | 499 | | // Collect types from all referenced assemblies |
| | 221264 | 500 | | foreach (var reference in compilation.References) |
| | | 501 | | { |
| | 109981 | 502 | | if (compilation.GetAssemblyOrModuleSymbol(reference) is IAssemblySymbol assemblySymbol) |
| | | 503 | | { |
| | | 504 | | // Skip assemblies that already have [GenerateTypeRegistry] — those assemblies |
| | | 505 | | // register their own types at runtime via their own TypeRegistry and cascade |
| | | 506 | | // loading. Scanning them here would trigger false NDLRGEN001 errors for their |
| | | 507 | | // internal types. |
| | 109673 | 508 | | if (TypeDiscoveryHelper.HasGenerateTypeRegistryAttribute(assemblySymbol)) |
| | | 509 | | continue; |
| | | 510 | | |
| | | 511 | | // For referenced assemblies, they use their own generated namespace |
| | 109654 | 512 | | var refSafeAssemblyName = GeneratorHelpers.SanitizeIdentifier(assemblySymbol.Name); |
| | 109654 | 513 | | var refGeneratedNamespace = $"{refSafeAssemblyName}.Generated"; |
| | 109654 | 514 | | CollectTypesFromAssembly(assemblySymbol, prefixList, excludePrefixList, injectableTypes, pluginTypes, de |
| | | 515 | | } |
| | | 516 | | } |
| | | 517 | | |
| | | 518 | | // Expand open generic decorators into closed decorator registrations |
| | 651 | 519 | | if (openDecorators.Count > 0) |
| | | 520 | | { |
| | 6 | 521 | | CodeGen.DecoratorsCodeGenerator.ExpandOpenDecorators(injectableTypes, openDecorators, decorators); |
| | | 522 | | } |
| | | 523 | | |
| | | 524 | | // Expand [RegisterClosedOverImplementationsOf] markers into closed composition registrations. |
| | 651 | 525 | | var composedRegistrations = new List<DiscoveredComposedRegistration>(); |
| | 651 | 526 | | var composedConstraintViolations = new List<ComposedConstraintViolation>(); |
| | 651 | 527 | | if (composedMarkers.Count > 0) |
| | | 528 | | { |
| | 68 | 529 | | ComposedRegistrationDiscoveryHelper.Expand( |
| | 68 | 530 | | composedMarkers, |
| | 68 | 531 | | composedCandidateTypes, |
| | 68 | 532 | | composedRegistrations, |
| | 68 | 533 | | composedConstraintViolations); |
| | | 534 | | } |
| | | 535 | | |
| | | 536 | | // Filter out nested options types (types used as properties in other options types) |
| | 651 | 537 | | if (options.Count > 1) |
| | | 538 | | { |
| | 19 | 539 | | options = OptionsDiscoveryHelper.FilterNestedOptions(options, compilation); |
| | | 540 | | } |
| | | 541 | | |
| | | 542 | | // Check for referenced assemblies with internal plugin types but no [GenerateTypeRegistry] |
| | 651 | 543 | | var missingTypeRegistryPlugins = new List<MissingTypeRegistryPlugin>(); |
| | 221264 | 544 | | foreach (var reference in compilation.References) |
| | | 545 | | { |
| | 109981 | 546 | | if (compilation.GetAssemblyOrModuleSymbol(reference) is IAssemblySymbol assemblySymbol) |
| | | 547 | | { |
| | | 548 | | // Skip assemblies that already have [GenerateTypeRegistry] |
| | 109673 | 549 | | if (TypeDiscoveryHelper.HasGenerateTypeRegistryAttribute(assemblySymbol)) |
| | | 550 | | continue; |
| | | 551 | | |
| | | 552 | | // Look for internal types that implement Needlr plugin interfaces |
| | 5380482 | 553 | | foreach (var typeSymbol in TypeDiscoveryHelper.GetAllTypes(assemblySymbol.GlobalNamespace)) |
| | | 554 | | { |
| | 2580587 | 555 | | if (!TypeDiscoveryHelper.IsInternalOrLessAccessible(typeSymbol)) |
| | | 556 | | continue; |
| | | 557 | | |
| | 122663 | 558 | | if (!TypeDiscoveryHelper.ImplementsNeedlrPluginInterface(typeSymbol)) |
| | | 559 | | continue; |
| | | 560 | | |
| | | 561 | | // This is an internal plugin type in an assembly without [GenerateTypeRegistry] |
| | 1 | 562 | | var typeName = TypeDiscoveryHelper.GetFullyQualifiedName(typeSymbol); |
| | 1 | 563 | | missingTypeRegistryPlugins.Add(new MissingTypeRegistryPlugin(typeName, assemblySymbol.Name)); |
| | | 564 | | } |
| | | 565 | | } |
| | | 566 | | } |
| | | 567 | | |
| | 651 | 568 | | return new DiscoveryResult(injectableTypes, pluginTypes, decorators, inaccessibleTypes, missingTypeRegistryPlugi |
| | | 569 | | } |
| | | 570 | | |
| | | 571 | | private static void CollectTypesFromAssembly( |
| | | 572 | | IAssemblySymbol assembly, |
| | | 573 | | IReadOnlyList<string>? namespacePrefixes, |
| | | 574 | | IReadOnlyList<string>? excludeNamespacePrefixes, |
| | | 575 | | List<DiscoveredType> injectableTypes, |
| | | 576 | | List<DiscoveredPlugin> pluginTypes, |
| | | 577 | | List<DiscoveredDecorator> decorators, |
| | | 578 | | List<DiscoveredOpenDecorator> openDecorators, |
| | | 579 | | List<DiscoveredInterceptedService> interceptedServices, |
| | | 580 | | List<DiscoveredFactory> factories, |
| | | 581 | | List<DiscoveredOptions> options, |
| | | 582 | | List<DiscoveredHostedService> hostedServices, |
| | | 583 | | List<DiscoveredProvider> providers, |
| | | 584 | | List<DiscoveredHttpClient> httpClients, |
| | | 585 | | List<InaccessibleType> inaccessibleTypes, |
| | | 586 | | List<DiscoveredComposedMarker> composedMarkers, |
| | | 587 | | List<INamedTypeSymbol> composedCandidateTypes, |
| | | 588 | | Compilation compilation, |
| | | 589 | | bool isCurrentAssembly, |
| | | 590 | | string generatedNamespace) |
| | | 591 | | { |
| | 5386686 | 592 | | foreach (var typeSymbol in TypeDiscoveryHelper.GetAllTypes(assembly.GlobalNamespace)) |
| | | 593 | | { |
| | 2583040 | 594 | | if (!TypeDiscoveryHelper.MatchesNamespacePrefix(typeSymbol, namespacePrefixes)) |
| | | 595 | | continue; |
| | | 596 | | |
| | 1887888 | 597 | | if (TypeDiscoveryHelper.MatchesExclusionFilter(typeSymbol, excludeNamespacePrefixes)) |
| | | 598 | | continue; |
| | | 599 | | |
| | | 600 | | // .NET MAUI per-platform application entry points are framework-owned and carry |
| | | 601 | | // platform-generated interop members that are inaccessible from generated code. |
| | | 602 | | // Scanning them breaks the head build, so skip them before any discovery path runs. |
| | 1887887 | 603 | | if (TypeDiscoveryHelper.IsMauiPlatformEntryType(typeSymbol)) |
| | | 604 | | continue; |
| | | 605 | | |
| | | 606 | | // For referenced assemblies, check if the type would be registerable but is inaccessible |
| | 1887883 | 607 | | if (!isCurrentAssembly && TypeDiscoveryHelper.IsInternalOrLessAccessible(typeSymbol)) |
| | | 608 | | { |
| | | 609 | | // Check if this type would have been registered if it were accessible |
| | 90261 | 610 | | if (TypeDiscoveryHelper.WouldBeInjectableIgnoringAccessibility(typeSymbol) || |
| | 90261 | 611 | | TypeDiscoveryHelper.WouldBePluginIgnoringAccessibility(typeSymbol, compilation.Assembly)) |
| | | 612 | | { |
| | 2853 | 613 | | var typeName = TypeDiscoveryHelper.GetFullyQualifiedName(typeSymbol); |
| | 2853 | 614 | | inaccessibleTypes.Add(new InaccessibleType(typeName, assembly.Name)); |
| | | 615 | | } |
| | 2853 | 616 | | continue; // Skip further processing for inaccessible types |
| | | 617 | | } |
| | | 618 | | |
| | | 619 | | // Check for [Options] attribute |
| | 1797622 | 620 | | if (OptionsAttributeHelper.HasOptionsAttribute(typeSymbol)) |
| | | 621 | | { |
| | 178 | 622 | | var typeName = TypeDiscoveryHelper.GetFullyQualifiedName(typeSymbol); |
| | 178 | 623 | | var optionsAttrs = OptionsAttributeHelper.GetOptionsAttributes(typeSymbol); |
| | 178 | 624 | | var sourceFilePath = typeSymbol.Locations.FirstOrDefault()?.SourceTree?.FilePath; |
| | | 625 | | |
| | | 626 | | // Extract bindable properties for AOT code generation |
| | 178 | 627 | | var properties = OptionsDiscoveryHelper.ExtractBindableProperties(typeSymbol); |
| | | 628 | | |
| | | 629 | | // Detect positional record (record with primary constructor parameters) |
| | 178 | 630 | | var positionalRecordInfo = OptionsDiscoveryHelper.DetectPositionalRecord(typeSymbol, properties); |
| | | 631 | | |
| | 724 | 632 | | foreach (var optionsAttr in optionsAttrs) |
| | | 633 | | { |
| | | 634 | | // Determine validator type and method |
| | 184 | 635 | | var validatorTypeSymbol = optionsAttr.ValidatorType; |
| | 184 | 636 | | var targetType = validatorTypeSymbol ?? typeSymbol; // Look for method on options class or external |
| | 184 | 637 | | var methodName = optionsAttr.ValidateMethod ?? "Validate"; // Convention: "Validate" |
| | | 638 | | |
| | | 639 | | // Find validation method using convention-based discovery |
| | 184 | 640 | | var validatorMethodInfo = OptionsAttributeHelper.FindValidationMethod( |
| | 184 | 641 | | targetType, |
| | 184 | 642 | | typeSymbol, |
| | 184 | 643 | | methodName, |
| | 184 | 644 | | validatorTypeSymbol is not null, |
| | 184 | 645 | | optionsAttr.ValidateMethod is null); |
| | 184 | 646 | | OptionsValidatorInfo? validatorInfo = validatorMethodInfo.HasValue |
| | 184 | 647 | | ? new OptionsValidatorInfo( |
| | 184 | 648 | | validatorMethodInfo.Value.MethodName, |
| | 184 | 649 | | validatorMethodInfo.Value.IsStatic, |
| | 184 | 650 | | validatorMethodInfo.Value.UsesOptionsValidatorInterface) |
| | 184 | 651 | | : null; |
| | | 652 | | |
| | | 653 | | // Infer section name if not provided |
| | 184 | 654 | | var sectionName = optionsAttr.SectionName |
| | 184 | 655 | | ?? Helpers.OptionsNamingHelper.InferSectionName(typeSymbol.Name); |
| | | 656 | | |
| | 184 | 657 | | var validatorTypeName = validatorTypeSymbol != null |
| | 184 | 658 | | ? TypeDiscoveryHelper.GetFullyQualifiedName(validatorTypeSymbol) |
| | 184 | 659 | | : null; |
| | | 660 | | |
| | 184 | 661 | | options.Add(new DiscoveredOptions( |
| | 184 | 662 | | typeName, |
| | 184 | 663 | | sectionName, |
| | 184 | 664 | | optionsAttr.Name, |
| | 184 | 665 | | optionsAttr.ValidateOnStart, |
| | 184 | 666 | | assembly.Name, |
| | 184 | 667 | | sourceFilePath, |
| | 184 | 668 | | validatorInfo, |
| | 184 | 669 | | optionsAttr.ValidateMethod, |
| | 184 | 670 | | validatorTypeName, |
| | 184 | 671 | | positionalRecordInfo, |
| | 184 | 672 | | properties)); |
| | | 673 | | } |
| | | 674 | | } |
| | | 675 | | |
| | 1797622 | 676 | | var httpAttrInfo = |
| | 1797622 | 677 | | HttpClientOptionsAttributeHelper.GetHttpClientOptionsAttribute( |
| | 1797622 | 678 | | typeSymbol); |
| | 1797622 | 679 | | if (httpAttrInfo.HasValue) |
| | | 680 | | { |
| | 12 | 681 | | var clientNamePropResult = |
| | 12 | 682 | | HttpClientOptionsAttributeHelper.TryGetClientNameProperty( |
| | 12 | 683 | | typeSymbol, |
| | 12 | 684 | | out var literalValue); |
| | 12 | 685 | | var propertyNameFromType = |
| | 12 | 686 | | clientNamePropResult == ClientNamePropertyResult.Literal |
| | 12 | 687 | | ? literalValue |
| | 12 | 688 | | : null; |
| | | 689 | | |
| | 12 | 690 | | if (HttpClientOptionsAttributeHelper.TryResolveClientName( |
| | 12 | 691 | | typeSymbol, |
| | 12 | 692 | | httpAttrInfo.Value, |
| | 12 | 693 | | propertyNameFromType, |
| | 12 | 694 | | out var resolvedClientName)) |
| | | 695 | | { |
| | 11 | 696 | | var httpSectionName = |
| | 11 | 697 | | HttpClientOptionsAttributeHelper.ResolveSectionName( |
| | 11 | 698 | | httpAttrInfo.Value, |
| | 11 | 699 | | resolvedClientName); |
| | 11 | 700 | | var httpTypeName = |
| | 11 | 701 | | TypeDiscoveryHelper.GetFullyQualifiedName(typeSymbol); |
| | 11 | 702 | | var httpSourceFilePath = |
| | 11 | 703 | | typeSymbol.Locations.FirstOrDefault()? |
| | 11 | 704 | | .SourceTree?.FilePath; |
| | 11 | 705 | | var capabilities = |
| | 11 | 706 | | HttpClientOptionsAttributeHelper.DetectCapabilities( |
| | 11 | 707 | | typeSymbol); |
| | | 708 | | |
| | 11 | 709 | | httpClients.Add(new DiscoveredHttpClient( |
| | 11 | 710 | | httpTypeName, |
| | 11 | 711 | | resolvedClientName, |
| | 11 | 712 | | httpSectionName, |
| | 11 | 713 | | assembly.Name, |
| | 11 | 714 | | capabilities, |
| | 11 | 715 | | httpSourceFilePath)); |
| | | 716 | | } |
| | | 717 | | } |
| | | 718 | | |
| | | 719 | | // Check for [GenerateFactory] attribute - these types get factories instead of direct registration |
| | 1797622 | 720 | | if (FactoryDiscoveryHelper.HasGenerateFactoryAttribute(typeSymbol)) |
| | | 721 | | { |
| | 91 | 722 | | var factoryConstructors = FactoryDiscoveryHelper.GetFactoryConstructors(typeSymbol); |
| | 91 | 723 | | if (factoryConstructors.Count > 0) |
| | | 724 | | { |
| | | 725 | | // Has at least one constructor with runtime params - generate factory |
| | 88 | 726 | | var typeName = TypeDiscoveryHelper.GetFullyQualifiedName(typeSymbol); |
| | 88 | 727 | | var interfaces = TypeDiscoveryHelper.GetRegisterableInterfaces(typeSymbol, compilation.Assembly); |
| | 106 | 728 | | var interfaceNames = interfaces.Select(i => TypeDiscoveryHelper.GetFullyQualifiedName(i)).ToArray(); |
| | 88 | 729 | | var generationMode = FactoryDiscoveryHelper.GetFactoryGenerationMode(typeSymbol); |
| | 88 | 730 | | var returnTypeOverride = FactoryDiscoveryHelper.GetFactoryReturnInterfaceType(typeSymbol); |
| | 88 | 731 | | var sourceFilePath = typeSymbol.Locations.FirstOrDefault()?.SourceTree?.FilePath; |
| | | 732 | | |
| | 88 | 733 | | factories.Add(new DiscoveredFactory( |
| | 88 | 734 | | typeName, |
| | 88 | 735 | | interfaceNames, |
| | 88 | 736 | | assembly.Name, |
| | 88 | 737 | | generationMode, |
| | 88 | 738 | | factoryConstructors.ToArray(), |
| | 88 | 739 | | returnTypeOverride, |
| | 88 | 740 | | sourceFilePath)); |
| | | 741 | | |
| | 88 | 742 | | continue; // Don't add to injectable types - factory handles registration |
| | | 743 | | } |
| | | 744 | | // If no runtime params, fall through to normal direct-type registration. |
| | | 745 | | } |
| | | 746 | | |
| | | 747 | | // Check for DecoratorFor<T> attributes |
| | 1797534 | 748 | | var decoratorInfos = TypeDiscoveryHelper.GetDecoratorForAttributes(typeSymbol); |
| | 3595148 | 749 | | foreach (var decoratorInfo in decoratorInfos) |
| | | 750 | | { |
| | 40 | 751 | | var sourceFilePath = typeSymbol.Locations.FirstOrDefault()?.SourceTree?.FilePath; |
| | 40 | 752 | | decorators.Add(new DiscoveredDecorator( |
| | 40 | 753 | | decoratorInfo.DecoratorTypeName, |
| | 40 | 754 | | decoratorInfo.ServiceTypeName, |
| | 40 | 755 | | decoratorInfo.Order, |
| | 40 | 756 | | assembly.Name, |
| | 40 | 757 | | sourceFilePath)); |
| | | 758 | | } |
| | | 759 | | |
| | | 760 | | // Check for OpenDecoratorFor attributes (source-gen only open generic decorators) |
| | 1797534 | 761 | | var openDecoratorInfos = OpenDecoratorDiscoveryHelper.GetOpenDecoratorForAttributes(typeSymbol); |
| | 3595082 | 762 | | foreach (var openDecoratorInfo in openDecoratorInfos) |
| | | 763 | | { |
| | 7 | 764 | | var sourceFilePath = typeSymbol.Locations.FirstOrDefault()?.SourceTree?.FilePath; |
| | 7 | 765 | | openDecorators.Add(new DiscoveredOpenDecorator( |
| | 7 | 766 | | openDecoratorInfo.DecoratorType, |
| | 7 | 767 | | openDecoratorInfo.OpenGenericInterface, |
| | 7 | 768 | | openDecoratorInfo.Order, |
| | 7 | 769 | | assembly.Name, |
| | 7 | 770 | | sourceFilePath)); |
| | | 771 | | } |
| | | 772 | | |
| | | 773 | | // Check for RegisterClosedOverImplementationsOf attributes (source-gen only composition markers) |
| | 1797534 | 774 | | var composedMarkerInfos = ComposedRegistrationDiscoveryHelper.GetComposedMarkers(typeSymbol); |
| | 3595206 | 775 | | foreach (var composedMarkerInfo in composedMarkerInfos) |
| | | 776 | | { |
| | 69 | 777 | | var sourceFilePath = typeSymbol.Locations.FirstOrDefault()?.SourceTree?.FilePath; |
| | 69 | 778 | | composedMarkers.Add(new DiscoveredComposedMarker( |
| | 69 | 779 | | composedMarkerInfo.CompositionType, |
| | 69 | 780 | | composedMarkerInfo.SourceOpenGenericInterface, |
| | 69 | 781 | | composedMarkerInfo.AsServiceType, |
| | 69 | 782 | | composedMarkerInfo.Lifetime, |
| | 69 | 783 | | assembly.Name, |
| | 69 | 784 | | sourceFilePath)); |
| | | 785 | | } |
| | | 786 | | |
| | | 787 | | // Check for Intercept attributes and collect intercepted services |
| | 1797534 | 788 | | if (InterceptorDiscoveryHelper.HasInterceptAttributes(typeSymbol)) |
| | | 789 | | { |
| | 15 | 790 | | var lifetime = TypeDiscoveryHelper.DetermineLifetime(typeSymbol); |
| | 15 | 791 | | if (lifetime.HasValue) |
| | | 792 | | { |
| | 15 | 793 | | var classLevelInterceptors = InterceptorDiscoveryHelper.GetInterceptAttributes(typeSymbol); |
| | 15 | 794 | | var methodLevelInterceptors = InterceptorDiscoveryHelper.GetMethodLevelInterceptAttributes(typeSymbo |
| | 15 | 795 | | var methods = InterceptorDiscoveryHelper.GetInterceptedMethods(typeSymbol, classLevelInterceptors, m |
| | | 796 | | |
| | 15 | 797 | | if (methods.Count > 0) |
| | | 798 | | { |
| | 15 | 799 | | var typeName = TypeDiscoveryHelper.GetFullyQualifiedName(typeSymbol); |
| | 15 | 800 | | var interfaces = TypeDiscoveryHelper.GetRegisterableInterfaces(typeSymbol, compilation.Assembly) |
| | 30 | 801 | | var interfaceNames = interfaces.Select(i => TypeDiscoveryHelper.GetFullyQualifiedName(i)).ToArra |
| | | 802 | | |
| | | 803 | | // Collect all unique interceptor types |
| | 15 | 804 | | var allInterceptorTypes = classLevelInterceptors |
| | 15 | 805 | | .Concat(methodLevelInterceptors) |
| | 18 | 806 | | .Select(i => i.InterceptorTypeName) |
| | 15 | 807 | | .Distinct() |
| | 15 | 808 | | .ToArray(); |
| | | 809 | | |
| | 15 | 810 | | var interceptedSourceFilePath = typeSymbol.Locations.FirstOrDefault()?.SourceTree?.FilePath; |
| | | 811 | | |
| | 15 | 812 | | interceptedServices.Add(new DiscoveredInterceptedService( |
| | 15 | 813 | | typeName, |
| | 15 | 814 | | interfaceNames, |
| | 15 | 815 | | assembly.Name, |
| | 15 | 816 | | lifetime.Value, |
| | 15 | 817 | | methods.ToArray(), |
| | 15 | 818 | | allInterceptorTypes, |
| | 15 | 819 | | interceptedSourceFilePath)); |
| | | 820 | | } |
| | | 821 | | } |
| | | 822 | | } |
| | | 823 | | |
| | | 824 | | // Check for injectable types (but skip types that are providers, which are handled separately) |
| | 1797534 | 825 | | if (TypeDiscoveryHelper.IsInjectableType(typeSymbol, isCurrentAssembly) && !ProviderDiscoveryHelper.HasProvi |
| | | 826 | | { |
| | | 827 | | // Determine lifetime first - only include types that are actually injectable |
| | 504404 | 828 | | var lifetime = TypeDiscoveryHelper.DetermineLifetime(typeSymbol); |
| | 504404 | 829 | | if (lifetime.HasValue) |
| | | 830 | | { |
| | 287548 | 831 | | var interfaces = TypeDiscoveryHelper.GetRegisterableInterfaces(typeSymbol, compilation.Assembly); |
| | 287548 | 832 | | var typeName = TypeDiscoveryHelper.GetFullyQualifiedName(typeSymbol); |
| | 287985 | 833 | | var interfaceNames = interfaces.Select(i => TypeDiscoveryHelper.GetFullyQualifiedName(i)).ToArray(); |
| | | 834 | | |
| | | 835 | | // Capture interface locations for navigation |
| | 287548 | 836 | | var interfaceInfos = interfaces.Select(i => |
| | 287548 | 837 | | { |
| | 437 | 838 | | var ifaceLocation = i.Locations.FirstOrDefault(); |
| | 437 | 839 | | var ifaceFilePath = ifaceLocation?.SourceTree?.FilePath; |
| | 437 | 840 | | var ifaceLine = ifaceLocation?.GetLineSpan().StartLinePosition.Line + 1 ?? 0; |
| | 437 | 841 | | return new InterfaceInfo(TypeDiscoveryHelper.GetFullyQualifiedName(i), ifaceFilePath, ifaceLine) |
| | 287548 | 842 | | }).ToArray(); |
| | | 843 | | |
| | | 844 | | // Check for [DeferToContainer] attribute - use declared types instead of discovered constructors |
| | 287548 | 845 | | var deferredParams = TypeDiscoveryHelper.GetDeferToContainerParameterTypes(typeSymbol); |
| | | 846 | | TypeDiscoveryHelper.ConstructorParameterInfo[] constructorParams; |
| | 287548 | 847 | | if (deferredParams != null) |
| | | 848 | | { |
| | | 849 | | // DeferToContainer doesn't support keyed services - convert to simple params |
| | 10 | 850 | | constructorParams = deferredParams.Select(t => new TypeDiscoveryHelper.ConstructorParameterInfo( |
| | | 851 | | } |
| | | 852 | | else |
| | | 853 | | { |
| | | 854 | | // [GenerateConstructor]/field-triggered types get their constructor |
| | | 855 | | // emitted by a sibling generator pass this compilation can't see yet. |
| | | 856 | | // Use the same field-derived model instead of the symbol-based |
| | | 857 | | // constructor lookup, which would otherwise still see only the |
| | | 858 | | // implicit parameterless constructor. |
| | 287543 | 859 | | constructorParams = ConstructorGenerationDiscoveryHelper.TryGetEffectiveConstructorParameters(ty |
| | 287543 | 860 | | ?? TypeDiscoveryHelper.GetBestConstructorParametersWithKeys(typeSymbol)?.ToArray() ?? []; |
| | | 861 | | } |
| | | 862 | | |
| | | 863 | | // Get source file path and line for breadcrumbs (null for external assemblies) |
| | 287548 | 864 | | var location = typeSymbol.Locations.FirstOrDefault(); |
| | 287548 | 865 | | var sourceFilePath = location?.SourceTree?.FilePath; |
| | 287548 | 866 | | var sourceLine = location?.GetLineSpan().StartLinePosition.Line + 1 ?? 0; // Convert to 1-based |
| | | 867 | | |
| | | 868 | | // Get [Keyed] attribute keys |
| | 287548 | 869 | | var serviceKeys = TypeDiscoveryHelper.GetKeyedServiceKeys(typeSymbol); |
| | | 870 | | |
| | | 871 | | // Check if this type implements IDisposable or IAsyncDisposable |
| | 287548 | 872 | | var isDisposable = TypeDiscoveryHelper.IsDisposableType(typeSymbol); |
| | | 873 | | |
| | 287548 | 874 | | injectableTypes.Add(new DiscoveredType(typeName, interfaceNames, assembly.Name, lifetime.Value, cons |
| | | 875 | | |
| | | 876 | | // Every injectable type is a candidate implementation for [RegisterClosedOverImplementationsOf] |
| | | 877 | | // expansion. Tying collection to the injectable-registration site means a composition composes |
| | | 878 | | // over exactly the set Needlr registers — current assembly plus referenced libraries — so |
| | | 879 | | // cross-assembly definitions are handled the same way decorators expand over injectable types. |
| | 287548 | 880 | | composedCandidateTypes.Add(typeSymbol); |
| | | 881 | | } |
| | | 882 | | } |
| | | 883 | | |
| | | 884 | | // Check for hosted service types (BackgroundService or IHostedService implementations) |
| | 1797534 | 885 | | if (TypeDiscoveryHelper.IsHostedServiceType(typeSymbol, isCurrentAssembly)) |
| | | 886 | | { |
| | | 887 | | // Use the same field-derived model that drives constructor generation |
| | | 888 | | // when one applies, since the symbol-based lookup can't see the |
| | | 889 | | // sibling generator's constructor output within this compilation. |
| | 10 | 890 | | var effectiveGeneratedParams = ConstructorGenerationDiscoveryHelper.TryGetEffectiveConstructorParameters |
| | 10 | 891 | | var isGeneratedButNotInjectable = effectiveGeneratedParams is null && |
| | 10 | 892 | | ConstructorGenerationDiscoveryHelper.TryGetModel(typeSymbol) != null; |
| | | 893 | | |
| | | 894 | | // A type eligible for constructor generation whose generated constructor |
| | | 895 | | // isn't fully container-resolvable (e.g. a field-triggered guard on a |
| | | 896 | | // plain string) must not fall back to the symbol-based scan below: that |
| | | 897 | | // scan only sees the implicit parameterless constructor that exists |
| | | 898 | | // before the sibling GeneratedConstructorGenerator pass runs, so it would |
| | | 899 | | // register `services.AddSingleton<T>()` for a hosted service whose real |
| | | 900 | | // (generated) constructor the container can never actually activate. |
| | | 901 | | // Skip automatic hosted registration entirely rather than emit metadata |
| | | 902 | | // — and a registration call — for an unactivatable worker. |
| | 10 | 903 | | if (!isGeneratedButNotInjectable) |
| | | 904 | | { |
| | 9 | 905 | | var typeName = TypeDiscoveryHelper.GetFullyQualifiedName(typeSymbol); |
| | 9 | 906 | | var constructorParams = effectiveGeneratedParams?.ToArray() |
| | 9 | 907 | | ?? TypeDiscoveryHelper.GetBestConstructorParametersWithKeys(typeSymbol)?.ToArray() ?? []; |
| | 9 | 908 | | var sourceFilePath = typeSymbol.Locations.FirstOrDefault()?.SourceTree?.FilePath; |
| | | 909 | | |
| | 9 | 910 | | hostedServices.Add(new DiscoveredHostedService( |
| | 9 | 911 | | typeName, |
| | 9 | 912 | | assembly.Name, |
| | 9 | 913 | | GeneratorLifetime.Singleton, // Hosted services are always singleton |
| | 9 | 914 | | constructorParams, |
| | 9 | 915 | | sourceFilePath)); |
| | | 916 | | } |
| | | 917 | | } |
| | | 918 | | |
| | | 919 | | // Check for [Provider] attribute |
| | 1797534 | 920 | | if (ProviderDiscoveryHelper.HasProviderAttribute(typeSymbol)) |
| | | 921 | | { |
| | 20 | 922 | | var discoveredProvider = ProviderDiscoveryHelper.DiscoverProvider(typeSymbol, assembly.Name, generatedNa |
| | 20 | 923 | | if (discoveredProvider.HasValue) |
| | | 924 | | { |
| | 20 | 925 | | providers.Add(discoveredProvider.Value); |
| | | 926 | | } |
| | | 927 | | } |
| | | 928 | | |
| | | 929 | | // Check for plugin types (concrete class with parameterless ctor and interfaces) |
| | 1797534 | 930 | | if (TypeDiscoveryHelper.IsPluginType(typeSymbol, isCurrentAssembly)) |
| | | 931 | | { |
| | 500086 | 932 | | var pluginInterfaces = TypeDiscoveryHelper.GetPluginInterfaces(typeSymbol, compilation.Assembly); |
| | 500086 | 933 | | if (pluginInterfaces.Count > 0) |
| | | 934 | | { |
| | 1858 | 935 | | var typeName = TypeDiscoveryHelper.GetFullyQualifiedName(typeSymbol); |
| | 3730 | 936 | | var interfaceNames = pluginInterfaces.Select(i => TypeDiscoveryHelper.GetFullyQualifiedName(i)).ToAr |
| | 1858 | 937 | | var attributeNames = TypeDiscoveryHelper.GetPluginAttributes(typeSymbol).ToArray(); |
| | 1858 | 938 | | var sourceFilePath = typeSymbol.Locations.FirstOrDefault()?.SourceTree?.FilePath; |
| | 1858 | 939 | | var order = PluginOrderHelper.GetPluginOrder(typeSymbol); |
| | | 940 | | |
| | 1858 | 941 | | pluginTypes.Add(new DiscoveredPlugin(typeName, interfaceNames, assembly.Name, attributeNames, source |
| | | 942 | | } |
| | | 943 | | } |
| | | 944 | | |
| | | 945 | | } |
| | 110303 | 946 | | } |
| | | 947 | | |
| | | 948 | | private static string GenerateTypeRegistrySource( |
| | | 949 | | GeneratedRegistrationPlan registrationPlan, |
| | | 950 | | BreadcrumbWriter breadcrumbs, |
| | | 951 | | string? projectDirectory) |
| | | 952 | | { |
| | 597 | 953 | | var builder = new StringBuilder(); |
| | 597 | 954 | | var discoveryResult = registrationPlan.DiscoveryResult; |
| | 597 | 955 | | var assemblyName = registrationPlan.AssemblyName; |
| | 597 | 956 | | var safeAssemblyName = GeneratorHelpers.SanitizeIdentifier(assemblyName); |
| | 597 | 957 | | var isAotProject = registrationPlan.IsAotProject; |
| | 597 | 958 | | var hasConfigBoundRegistrations = |
| | 597 | 959 | | registrationPlan.HasConfigBoundRegistrations; |
| | | 960 | | |
| | 597 | 961 | | breadcrumbs.WriteFileHeader(builder, assemblyName, "Needlr Type Registry"); |
| | 597 | 962 | | builder.AppendLine("#nullable enable"); |
| | 597 | 963 | | builder.AppendLine(); |
| | 597 | 964 | | builder.AppendLine("using System;"); |
| | 597 | 965 | | builder.AppendLine("using System.Collections.Generic;"); |
| | 597 | 966 | | builder.AppendLine(); |
| | 597 | 967 | | if (hasConfigBoundRegistrations) |
| | | 968 | | { |
| | 162 | 969 | | builder.AppendLine("using Microsoft.Extensions.Configuration;"); |
| | 162 | 970 | | if (isAotProject || |
| | 162 | 971 | | registrationPlan.HasHttpClientRegistrations) |
| | | 972 | | { |
| | 89 | 973 | | builder.AppendLine("using Microsoft.Extensions.Options;"); |
| | | 974 | | } |
| | | 975 | | } |
| | 597 | 976 | | builder.AppendLine("using Microsoft.Extensions.DependencyInjection;"); |
| | 597 | 977 | | builder.AppendLine(); |
| | 597 | 978 | | builder.AppendLine("using NexusLabs.Needlr;"); |
| | 597 | 979 | | builder.AppendLine("using NexusLabs.Needlr.Generators;"); |
| | 597 | 980 | | builder.AppendLine(); |
| | 597 | 981 | | builder.AppendLine($"namespace {safeAssemblyName}.Generated;"); |
| | 597 | 982 | | builder.AppendLine(); |
| | 597 | 983 | | builder.AppendLine("/// <summary>"); |
| | 597 | 984 | | builder.AppendLine("/// Compile-time generated registry of injectable types and plugins."); |
| | 597 | 985 | | builder.AppendLine("/// This eliminates the need for runtime reflection-based type discovery."); |
| | 597 | 986 | | builder.AppendLine("/// </summary>"); |
| | 597 | 987 | | builder.AppendLine("[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"NexusLabs.Needlr.Generators\", \"1 |
| | 597 | 988 | | builder.AppendLine("public static class TypeRegistry"); |
| | 597 | 989 | | builder.AppendLine("{"); |
| | | 990 | | |
| | 597 | 991 | | CodeGen.InjectableTypesCodeGenerator.GenerateInjectableTypesArray(builder, discoveryResult.InjectableTypes, brea |
| | 597 | 992 | | builder.AppendLine(); |
| | 597 | 993 | | CodeGen.PluginsCodeGenerator.GeneratePluginTypesArray(builder, discoveryResult.PluginTypes, breadcrumbs, project |
| | | 994 | | |
| | 597 | 995 | | builder.AppendLine(); |
| | 597 | 996 | | builder.AppendLine(" /// <summary>"); |
| | 597 | 997 | | builder.AppendLine(" /// Gets all injectable types discovered at compile time."); |
| | 597 | 998 | | builder.AppendLine(" /// </summary>"); |
| | 597 | 999 | | builder.AppendLine(" /// <returns>A read-only list of injectable type information.</returns>"); |
| | 597 | 1000 | | builder.AppendLine(" public static IReadOnlyList<InjectableTypeInfo> GetInjectableTypes() => _types;"); |
| | 597 | 1001 | | builder.AppendLine(); |
| | 597 | 1002 | | builder.AppendLine(" /// <summary>"); |
| | 597 | 1003 | | builder.AppendLine(" /// Gets all plugin types discovered at compile time."); |
| | 597 | 1004 | | builder.AppendLine(" /// </summary>"); |
| | 597 | 1005 | | builder.AppendLine(" /// <returns>A read-only list of plugin type information.</returns>"); |
| | 597 | 1006 | | builder.AppendLine(" public static IReadOnlyList<PluginTypeInfo> GetPluginTypes() => _plugins;"); |
| | | 1007 | | |
| | 597 | 1008 | | if (hasConfigBoundRegistrations) |
| | | 1009 | | { |
| | 162 | 1010 | | builder.AppendLine(); |
| | 162 | 1011 | | GenerateRegisterOptionsMethod(builder, discoveryResult.Options, discoveryResult.HttpClients, safeAssemblyNam |
| | | 1012 | | } |
| | | 1013 | | |
| | 597 | 1014 | | if (registrationPlan.HasProviderRegistrations) |
| | | 1015 | | { |
| | 18 | 1016 | | builder.AppendLine(); |
| | 18 | 1017 | | CodeGen.DecoratorsCodeGenerator.GenerateRegisterProvidersMethod( |
| | 18 | 1018 | | builder, |
| | 18 | 1019 | | registrationPlan.EmittedProviders, |
| | 18 | 1020 | | safeAssemblyName, |
| | 18 | 1021 | | breadcrumbs, |
| | 18 | 1022 | | projectDirectory); |
| | | 1023 | | } |
| | | 1024 | | |
| | 597 | 1025 | | builder.AppendLine(); |
| | 597 | 1026 | | CodeGen.DecoratorsCodeGenerator.GenerateApplyDecoratorsMethod(builder, discoveryResult.Decorators, discoveryResu |
| | | 1027 | | |
| | 597 | 1028 | | if (discoveryResult.ComposedRegistrations.Count > 0) |
| | | 1029 | | { |
| | 43 | 1030 | | builder.AppendLine(); |
| | 43 | 1031 | | CodeGen.ComposedRegistrationsCodeGenerator.GenerateRegisterComposedTypesMethod(builder, discoveryResult.Comp |
| | | 1032 | | } |
| | | 1033 | | |
| | 597 | 1034 | | if (discoveryResult.HostedServices.Count > 0) |
| | | 1035 | | { |
| | 8 | 1036 | | builder.AppendLine(); |
| | 8 | 1037 | | CodeGen.DecoratorsCodeGenerator.GenerateRegisterHostedServicesMethod(builder, discoveryResult.HostedServices |
| | | 1038 | | } |
| | | 1039 | | |
| | 597 | 1040 | | builder.AppendLine("}"); |
| | | 1041 | | |
| | 597 | 1042 | | return builder.ToString(); |
| | | 1043 | | } |
| | | 1044 | | |
| | | 1045 | | private static void GenerateRegisterOptionsMethod(StringBuilder builder, IReadOnlyList<DiscoveredOptions> options, I |
| | | 1046 | | { |
| | 162 | 1047 | | builder.AppendLine(" /// <summary>"); |
| | 162 | 1048 | | builder.AppendLine(" /// Registers all discovered options types with the service collection."); |
| | 162 | 1049 | | builder.AppendLine(" /// This binds configuration sections to strongly-typed options classes,"); |
| | 162 | 1050 | | builder.AppendLine(" /// and wires up named HttpClient registrations for [HttpClientOptions] types."); |
| | 162 | 1051 | | builder.AppendLine(" /// </summary>"); |
| | 162 | 1052 | | builder.AppendLine(" /// <param name=\"services\">The service collection to configure.</param>"); |
| | 162 | 1053 | | builder.AppendLine(" /// <param name=\"configuration\">The configuration root to bind options from.</param>") |
| | 162 | 1054 | | builder.AppendLine(" public static void RegisterOptions(IServiceCollection services, IConfiguration configura |
| | 162 | 1055 | | builder.AppendLine(" {"); |
| | | 1056 | | |
| | 162 | 1057 | | if (options.Count == 0 && httpClients.Count == 0) |
| | | 1058 | | { |
| | 0 | 1059 | | breadcrumbs.WriteInlineComment(builder, " ", "No options or HttpClient types discovered"); |
| | | 1060 | | } |
| | | 1061 | | else |
| | | 1062 | | { |
| | 162 | 1063 | | if (options.Count > 0) |
| | | 1064 | | { |
| | 157 | 1065 | | if (isAotProject) |
| | | 1066 | | { |
| | 83 | 1067 | | CodeGen.OptionsCodeGenerator.GenerateAotOptionsRegistration(builder, options, safeAssemblyName, brea |
| | | 1068 | | } |
| | | 1069 | | else |
| | | 1070 | | { |
| | 74 | 1071 | | CodeGen.OptionsCodeGenerator.GenerateReflectionOptionsRegistration(builder, options, safeAssemblyNam |
| | | 1072 | | } |
| | | 1073 | | } |
| | | 1074 | | |
| | 162 | 1075 | | if (httpClients.Count > 0) |
| | | 1076 | | { |
| | 6 | 1077 | | CodeGen.HttpClientCodeGenerator.EmitHttpClientRegistrations(builder, httpClients); |
| | | 1078 | | } |
| | | 1079 | | } |
| | | 1080 | | |
| | 162 | 1081 | | builder.AppendLine(" }"); |
| | 162 | 1082 | | } |
| | | 1083 | | |
| | | 1084 | | } |