Skip to content

Commit

Permalink
Update WhenAnyValueGenerator.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes committed Nov 28, 2024
1 parent 91c6218 commit 28d2dcb
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions ReactiveGenerator/WhenAnyValueGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,19 @@ private static void Execute(
{
if (classes.Count == 0) return;

// Group classes by type and source file
var classGroups = classes
.GroupBy(
c => (Type: c.Symbol, FilePath: c.Location.SourceTree?.FilePath ?? string.Empty),
(key, group) => new { TypeSymbol = key.Type, FilePath = key.FilePath },
new TypeAndPathComparer())
.ToList();

// Generate a separate file for each class group
foreach (var group in classGroups)
// Use a HashSet to track distinct types
var processedTypes = new HashSet<INamedTypeSymbol>(SymbolEqualityComparer.Default);

// Process each class, skipping duplicates
foreach (var (typeSymbol, _) in classes)
{
var source = GenerateExtensionsForClass(group.TypeSymbol);
var sourceFilePath = Path.GetFileNameWithoutExtension(group.FilePath);
var fileName = $"{group.TypeSymbol.Name}.{sourceFilePath}.WhenAnyValue.g.cs";
context.AddSource(fileName, SourceText.From(source, Encoding.UTF8));
// Only process each type once
if (processedTypes.Add(typeSymbol))
{
var source = GenerateExtensionsForClass(typeSymbol);
var fileName = $"{typeSymbol.Name}.WhenAnyValue.g.cs";
context.AddSource(fileName, SourceText.From(source, Encoding.UTF8));
}
}
}

Expand Down

0 comments on commit 28d2dcb

Please sign in to comment.