Skip to content

Commit

Permalink
Merge pull request #26 from flexpaymentsolutions/master
Browse files Browse the repository at this point in the history
Feature to turn off emitting ModuleInitializerAttribute when bringing your own polyfills
  • Loading branch information
ByronMayne authored Dec 5, 2024
2 parents 59502fa + 5e19b3d commit f978790
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
<Platforms>AnyCPU;x64</Platforms>
<AssemblySearchPath_UseOutDir>true</AssemblySearchPath_UseOutDir>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<!--Uncomment if bringing your own polyfills-->
<!--<SgfAddModuleInitializerAttribute>false</SgfAddModuleInitializerAttribute>-->
</PropertyGroup>
<ItemGroup>
<CompilerVisibleProperty Include="SgfAddModuleInitializerAttribute" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.3.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
Expand Down
8 changes: 7 additions & 1 deletion src/SourceGenerator.Foundations/HoistSourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
private void AddCoreTypes(SourceProductionContext context, AnalyzerConfigOptionsProvider optionsProvider)
{
string @namespace = "SGF";
context.AddSource("System_Runtime_CompilerServices_ModuleInitializerAttribute.g.cs", ModuleInitializerTemplate.Render());
var includeModuleInitializer = true;

if (optionsProvider.GlobalOptions.TryGetValue("build_property.SgfAddModuleInitializerAttribute", out var val))
if(!string.IsNullOrWhiteSpace(val)) bool.TryParse(val, out includeModuleInitializer);

if (includeModuleInitializer)
context.AddSource("System_Runtime_CompilerServices_ModuleInitializerAttribute.g.cs", ModuleInitializerTemplate.Render());
context.AddSource("SgfSourceGeneratorHoist.g.cs", SourceGeneratorHoistBase.RenderTemplate(@namespace));
context.AddSource("SgfAssemblyResolver.g.cs", AssemblyResolverTemplate.Render(@namespace));
}
Expand Down

0 comments on commit f978790

Please sign in to comment.