-
-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* TypeEqualityFinder now supports static Equals() methods in base classes. * Finding an equality comparer on a base type is cached now. * Type equality info gets stored in PropertyData now
- Loading branch information
1 parent
dada163
commit 165bf03
Showing
20 changed files
with
464 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Linq; | ||
|
||
public partial class ModuleWeaver | ||
{ | ||
public bool UseStaticEqualsFromBase; | ||
|
||
public void ResolveUseStaticEqualsFromBaseConfig() | ||
{ | ||
var value = Config?.Attributes("UseStaticEqualsFromBase").FirstOrDefault(); | ||
if (value != null) | ||
{ | ||
UseStaticEqualsFromBase = bool.Parse((string)value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace AssemblyWithBase.StaticEquals | ||
{ | ||
public class BaseClass | ||
{ | ||
private static bool staticEqualsCalled; | ||
public bool StaticEqualsCalled | ||
{ | ||
get => staticEqualsCalled; | ||
set => staticEqualsCalled = value; | ||
} | ||
|
||
public static bool Equals(BaseClass first, BaseClass second) | ||
{ | ||
staticEqualsCalled = true; | ||
|
||
if (ReferenceEquals(first, second)) | ||
return true; | ||
if (first == null || second == null) | ||
return false; | ||
|
||
return first.Equals(second); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
TestAssemblies/AssemblyWithBase/StaticEqualsGenericParent/BaseClass.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace AssemblyWithBase.StaticEqualsGenericParent | ||
{ | ||
public class BaseClass<T> | ||
{ | ||
private static bool staticEqualsCalled; | ||
public bool StaticEqualsCalled | ||
{ | ||
get => staticEqualsCalled; | ||
set => staticEqualsCalled = value; | ||
} | ||
|
||
public static bool Equals(BaseClass<T> first, BaseClass<T> second) | ||
{ | ||
staticEqualsCalled = true; | ||
|
||
if (ReferenceEquals(first, second)) | ||
return true; | ||
|
||
if (first == null || second == null) | ||
return false; | ||
|
||
return first.Equals(second); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
TestAssemblies/AssemblyWithBase/StaticEqualsGenericParent/BaseClass2.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace AssemblyWithBase.StaticEqualsGenericParent | ||
{ | ||
public class BaseClass2<T, TSomething> : BaseClass<TSomething> | ||
{ | ||
public T SomeProperty { get; set; } | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
TestAssemblies/AssemblyWithBase/StaticEqualsGenericParent/BaseClass3.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace AssemblyWithBase.StaticEqualsGenericParent | ||
{ | ||
public class BaseClass3<TFoo> : BaseClass2<TFoo, int> | ||
{ } | ||
} |
5 changes: 5 additions & 0 deletions
5
TestAssemblies/AssemblyWithBase/StaticEqualsGenericParent/ClassUsingBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace AssemblyWithBase.StaticEqualsGenericParent | ||
{ | ||
public class ClassUsingBaseEquals : BaseClass<int> | ||
{ } | ||
} |
26 changes: 26 additions & 0 deletions
26
TestAssemblies/AssemblyWithBase/StaticEqualsGenericParent/ClassWithOwnEquals.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace AssemblyWithBase.StaticEqualsGenericParent | ||
{ | ||
public class ClassWithOwnEquals : BaseClass<int> | ||
{ | ||
private static bool childStaticEqualsCalled; | ||
|
||
public bool ChildStaticEqualsCalled | ||
{ | ||
get => childStaticEqualsCalled; | ||
set => childStaticEqualsCalled = value; | ||
} | ||
|
||
public static bool Equals(ClassWithOwnEquals first, ClassWithOwnEquals second) | ||
{ | ||
childStaticEqualsCalled = true; | ||
|
||
if (ReferenceEquals(first, second)) | ||
return true; | ||
|
||
if (first == null || second == null) | ||
return false; | ||
|
||
return first.Equals(second); | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
TestAssemblies/AssemblyWithBase/StaticEqualsGenericParent/ClassWithTwoBaseClasses1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace AssemblyWithBase.StaticEqualsGenericParent | ||
{ | ||
public class ClassWithTwoBaseClasses1 : BaseClass2<int, string> | ||
{ } | ||
} |
5 changes: 5 additions & 0 deletions
5
TestAssemblies/AssemblyWithBase/StaticEqualsGenericParent/ClassWithTwoBaseClasses2.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace AssemblyWithBase.StaticEqualsGenericParent | ||
{ | ||
public class ClassWithTwoBaseClasses2 : BaseClass3<string> | ||
{ } | ||
} |
28 changes: 28 additions & 0 deletions
28
TestAssemblies/AssemblyWithBaseInDifferentModule/StaticEquals/StaticEquals.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.ComponentModel; | ||
using System.Runtime.CompilerServices; | ||
using AssemblyWithBase.StaticEquals; | ||
|
||
namespace AssemblyWithBaseInDifferentModule.StaticEquals | ||
{ | ||
public class StaticEquals : INotifyPropertyChanged | ||
{ | ||
private string property1; | ||
public string Property1 | ||
{ | ||
get => property1; | ||
set | ||
{ | ||
property1 = value; | ||
Property2 = new BaseClass(); | ||
} | ||
} | ||
|
||
public BaseClass Property2 { get; set; } | ||
|
||
public event PropertyChangedEventHandler PropertyChanged; | ||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) | ||
{ | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
TestAssemblies/AssemblyWithBaseInDifferentModule/StaticEqualsGenericParent/ArgsMapping1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.ComponentModel; | ||
using System.Runtime.CompilerServices; | ||
using AssemblyWithBase.StaticEqualsGenericParent; | ||
|
||
namespace AssemblyWithBaseInDifferentModule.StaticEqualsGenericParent | ||
{ | ||
public class ArgsMapping1 : INotifyPropertyChanged | ||
{ | ||
private string property1; | ||
public string Property1 | ||
{ | ||
get => property1; | ||
set | ||
{ | ||
property1 = value; | ||
Property2 = new ClassWithTwoBaseClasses1(); | ||
} | ||
} | ||
|
||
public ClassWithTwoBaseClasses1 Property2 { get; set; } | ||
|
||
public event PropertyChangedEventHandler PropertyChanged; | ||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) | ||
{ | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
TestAssemblies/AssemblyWithBaseInDifferentModule/StaticEqualsGenericParent/ArgsMapping2.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.ComponentModel; | ||
using System.Runtime.CompilerServices; | ||
using AssemblyWithBase.StaticEqualsGenericParent; | ||
|
||
namespace AssemblyWithBaseInDifferentModule.StaticEqualsGenericParent | ||
{ | ||
public class ArgsMapping2 : INotifyPropertyChanged | ||
{ | ||
private string property1; | ||
public string Property1 | ||
{ | ||
get => property1; | ||
set | ||
{ | ||
property1 = value; | ||
Property2 = new ClassWithTwoBaseClasses2(); | ||
} | ||
} | ||
|
||
public ClassWithTwoBaseClasses2 Property2 { get; set; } | ||
|
||
public event PropertyChangedEventHandler PropertyChanged; | ||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) | ||
{ | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
} | ||
} |
Oops, something went wrong.