Fix `ReflectionCacheGenerator` choking on dummy projects
This commit is contained in:
parent
fda159a8ca
commit
e5d641fc09
|
@ -6,7 +6,7 @@
|
|||
<AnalysisModeReliability>Recommended</AnalysisModeReliability>
|
||||
<AnalysisModePerformance>Recommended</AnalysisModePerformance>
|
||||
<AnalysisModeUsage>Recommended</AnalysisModeUsage>
|
||||
<EmitCompilerGeneratedFiles>false</EmitCompilerGeneratedFiles> <!-- enable to copy Roslyn Source Gemerators' outputs to $(ProjectDir)/obj/.../generated -->
|
||||
<EmitCompilerGeneratedFiles>false</EmitCompilerGeneratedFiles> <!-- enable to copy Roslyn Source Generators' outputs to $(ProjectDir)/obj/.../generated -->
|
||||
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
|
||||
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
|
||||
<ContinuousIntegrationBuild Condition=" '$(GITLAB_CI)' != '' Or '$(APPVEYOR)' != '' ">true</ContinuousIntegrationBuild>
|
||||
|
|
|
@ -27,6 +27,7 @@ public sealed class ReflectionCacheGenerator : IIncrementalGenerator
|
|||
|
||||
private string CalcNamespace()
|
||||
{
|
||||
if (_namespaces.Count is 0) return string.Empty; // this can happen if the Analyzer is applied to a project with no source files
|
||||
// black magic wizardry to find common prefix https://stackoverflow.com/a/35081977
|
||||
var ns = new string(_namespaces[0]
|
||||
.Substring(0, _namespaces.Min(s => s.Length))
|
||||
|
@ -63,6 +64,7 @@ public sealed class ReflectionCacheGenerator : IIncrementalGenerator
|
|||
|
||||
public void Execute(SourceProductionContext context, string nSpace)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(nSpace)) return; // see note in `CalcNamespace`
|
||||
var src = $@"#nullable enable
|
||||
|
||||
using System;
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue