Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equality comparers not detected in class hierarchies #332

Merged
merged 2 commits into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions PropertyChanged.Fody/TypeEqualityFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ public void FindComparisonMethods()
.First(x => x.Name == "Ordinal")
.Constant;

foreach (var node in NotifyNodes)
NotifyNodes.ForEach(FindComparisonMethods);

methodCache = null;
}

void FindComparisonMethods(TypeNode node)
{
foreach (var data in node.PropertyDatas)
{
foreach (var data in node.PropertyDatas)
{
data.EqualsMethod = FindTypeEquality(data);
}
data.EqualsMethod = FindTypeEquality(data);
}

methodCache = null;
node.Nodes.ForEach(FindComparisonMethods);
}

MethodReference FindTypeEquality(PropertyData propertyData)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace AssemblyWithBaseInDifferentModule.Hierarchy
{
using AssemblyWithBase.StaticEquals;

public class ChildClass : StaticEquals
{
private string property1;
public string Property1
{
get => property1;
set
{
property1 = value;
Property2 = new BaseClass();
}
}

public BaseClass Property2 { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace AssemblyWithBaseInDifferentModule.Hierarchy
{
public class StaticEquals : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
11 changes: 11 additions & 0 deletions Tests/AssemblyWithBaseInDifferentModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ public void StaticEquals()
instance.Property2.StaticEqualsCalled = false;
}

[Fact]
public void StaticEquals_Hierarchy()
{
Weave(true);
var instance = testResult.GetInstance("AssemblyWithBaseInDifferentModule.Hierarchy.ChildClass");
EventTester.TestProperty(instance, true);
Assert.NotNull(instance.Property2);
Assert.True(instance.Property2.StaticEqualsCalled);
instance.Property2.StaticEqualsCalled = false;
}

[Fact]
public void GenericStaticEquals()
{
Expand Down