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 5e3fd9c commit 9ba529b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions ReactiveGenerator/WhenAnyValueGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,25 @@ private static string GenerateExtensionsForClass(INamedTypeSymbol classSymbol)
}

sb.AppendLine("{");

// Generate class-specific extension class
sb.AppendLine($" public static class {classSymbol.Name}WhenAnyValueExtensions");
sb.AppendLine(" {");

var reactiveProperties = classSymbol.GetMembers()
.OfType<IPropertySymbol>()
.Where(p => p.GetAttributes()
.Any(a => a.AttributeClass?.Name is "ReactiveAttribute" or "Reactive"));
.Any(a => a.AttributeClass?.Name is "ReactiveAttribute" or "Reactive"))
.ToList();

// Generate methods for each property
var lastProperty = reactiveProperties.LastOrDefault();
foreach (var property in reactiveProperties)
{
GenerateWhenAnyValueMethod(sb, classSymbol, property);
sb.AppendLine();
// Only add newline if not the last property
if (!SymbolEqualityComparer.Default.Equals(property, lastProperty))
{
sb.AppendLine();
}
}

sb.AppendLine(" }");
Expand Down Expand Up @@ -159,7 +164,6 @@ private static void GenerateWhenAnyValueMethod(
sb.AppendLine(" }");
}


private const string UpdatedPropertyObserverSource = @"// <auto-generated/>
#nullable enable
Expand Down

0 comments on commit 9ba529b

Please sign in to comment.