Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/IncrementalGeneratorInitializationContextExtensions.cs')
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/IncrementalGeneratorInitializationContextExtensions.cs24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/IncrementalGeneratorInitializationContextExtensions.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/IncrementalGeneratorInitializationContextExtensions.cs
index 0b008795884..20a1818a33e 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/IncrementalGeneratorInitializationContextExtensions.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/IncrementalGeneratorInitializationContextExtensions.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
+using System.Collections.Immutable;
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis;
@@ -27,12 +28,21 @@ namespace Microsoft.Interop
public static void RegisterConcatenatedSyntaxOutputs<TNode>(this IncrementalGeneratorInitializationContext context, IncrementalValuesProvider<TNode> nodes, string fileName)
where TNode : SyntaxNode
{
- IncrementalValueProvider<string> generatedMethods = nodes
+ IncrementalValueProvider<ImmutableArray<string>> generatedMethods = nodes
.Select(
static (node, ct) => node.NormalizeWhitespace().ToFullString())
- .Collect()
- .Select(static (generatedSources, ct) =>
+ .Collect();
+
+ context.RegisterSourceOutput(generatedMethods,
+ (context, generatedSources) =>
{
+ // Don't generate a file if we don't have to, to avoid the extra IDE overhead once we have generated
+ // files in play.
+ if (generatedSources.IsEmpty)
+ {
+ return;
+ }
+
StringBuilder source = new();
// Mark in source that the file is auto-generated.
source.AppendLine("// <auto-generated/>");
@@ -40,13 +50,9 @@ namespace Microsoft.Interop
{
source.AppendLine(generated);
}
- return source.ToString();
- });
- context.RegisterSourceOutput(generatedMethods,
- (context, source) =>
- {
- context.AddSource(fileName, source);
+ // Once https://github.com/dotnet/roslyn/issues/61326 is resolved, we can avoid the ToString() here.
+ context.AddSource(fileName, source.ToString());
});
}
}