Skip to content

Commit

Permalink
Fix [AlsoBroadcastChange] breaking before other attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed May 10, 2022
1 parent 27fd6c3 commit 612a6ea
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,19 @@ internal static class Execute
{
// Gather dependent property and command names
if (TryGatherDependentPropertyChangedNames(fieldSymbol, attributeData, propertyChangedNames, builder) ||
TryGatherDependentCommandNames(fieldSymbol, attributeData, notifiedCommandNames, builder) ||
TryGetIsBroadcastingChanges(fieldSymbol, attributeData, builder, out alsoBroadcastChange))
TryGatherDependentCommandNames(fieldSymbol, attributeData, notifiedCommandNames, builder))
{
continue;
}

// Check whether the property should also broadcast changes
if (TryGetIsBroadcastingChanges(fieldSymbol, attributeData, builder, out bool isBroadcastTargetValid))
{
alsoBroadcastChange = isBroadcastTargetValid;

continue;
}

// Track the current validation attribute, if applicable
if (attributeData.AttributeClass?.InheritsFromFullyQualifiedName("global::System.ComponentModel.DataAnnotations.ValidationAttribute") == true)
{
Expand Down Expand Up @@ -332,21 +339,21 @@ bool IsCommandNameValidWithGeneratedMembers(string commandName)
/// <param name="fieldSymbol">The input <see cref="IFieldSymbol"/> instance to process.</param>
/// <param name="attributeData">The <see cref="AttributeData"/> instance for <paramref name="fieldSymbol"/>.</param>
/// <param name="diagnostics">The current collection of gathered diagnostics.</param>
/// <param name="alsoBroadcastChange">Whether or not the resulting property should also broadcast changes.</param>
/// <param name="isBroadcastTargetValid">Whether or not the the property is in a valid target that can broadcast changes.</param>
/// <returns>Whether or not the generated property for <paramref name="fieldSymbol"/> used <c>[AlsoBroadcastChange]</c>.</returns>
private static bool TryGetIsBroadcastingChanges(
IFieldSymbol fieldSymbol,
AttributeData attributeData,
ImmutableArray<Diagnostic>.Builder diagnostics,
out bool alsoBroadcastChange)
out bool isBroadcastTargetValid)
{
if (attributeData.AttributeClass?.HasFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.AlsoBroadcastChangeAttribute") == true)
{
// If the containing type is valid, track it
if (fieldSymbol.ContainingType.InheritsFromFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.ObservableRecipient") ||
fieldSymbol.ContainingType.HasOrInheritsAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.ObservableRecipientAttribute"))
{
alsoBroadcastChange = true;
isBroadcastTargetValid = true;

return true;
}
Expand All @@ -358,12 +365,12 @@ private static bool TryGetIsBroadcastingChanges(
fieldSymbol.ContainingType,
fieldSymbol.Name);

alsoBroadcastChange = false;
isBroadcastTargetValid = false;

return true;
}

alsoBroadcastChange = false;
isBroadcastTargetValid = false;

return false;
}
Expand Down

0 comments on commit 612a6ea

Please sign in to comment.