Skip to content

Commit

Permalink
Emit warning if signature of implicit On_PropertyName_Change method d…
Browse files Browse the repository at this point in the history
…oes not match.
  • Loading branch information
tom-englert committed Jun 7, 2021
1 parent d9296b4 commit 263935e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions PropertyChanged.Fody/PropertyWeaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void InjectAtIndex(int index)
foreach (var alsoNotifyForDefinition in propertyData.AlsoNotifyFor.Distinct())
{
var alsoNotifyMethods = GetMethodsForProperty(propertyData.ParentType, alsoNotifyForDefinition);

index = AddEventInvokeCall(index, alsoNotifyMethods, alsoNotifyForDefinition);
}

Expand Down Expand Up @@ -201,10 +201,13 @@ int AddOnChangedMethodCalls(int index, List<OnChangedMethod> onChangedMethods, P
break;

case OnChangedTypes.BeforeAfterTyped:
if (propertyDefinition.PropertyType.FullName == onChangedMethod.ArgumentTypeFullName)
if (propertyDefinition.PropertyType.FullName != onChangedMethod.ArgumentTypeFullName)
{
index = AddBeforeAfterOnChangedCall(index, propertyDefinition, onChangedMethod.MethodReference, true);
var methodDefinition = onChangedMethod.MethodDefinition;
moduleWeaver.EmitConditionalWarning(methodDefinition, $"Unsupported signature for a On_PropertyName_Changed method: {methodDefinition.Name} in {methodDefinition.DeclaringType.FullName}");
break;
}
index = AddBeforeAfterOnChangedCall(index, propertyDefinition, onChangedMethod.MethodReference, true);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/AssemblyToProcessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public void OnPropertyNameChangedMethodWithBeforeAfterTypedWithInvalidSignatureD

Assert.Null(instance.OnProperty1ChangedCalled);

Assert.DoesNotContain(testResult.Warnings, w => w.Text.ContainsWholeWord(nameof(ClassWithOnChangedBeforeAfterTypedInvalidSignatureDefault)));
Assert.Contains(testResult.Warnings, w => w.Text.ContainsWholeWord(nameof(ClassWithOnChangedBeforeAfterTypedInvalidSignatureDefault)));
}

[Fact]
Expand Down

0 comments on commit 263935e

Please sign in to comment.