ValeraT1982 / ObjectsComparer

C# Framework provides mechanism to compare complex objects, allows to override comparison rules for specific properties and types.
MIT License
352 stars 86 forks source link

Using attributes on fields and properties to exclude from comparison. #37

Closed aksar9211 closed 2 years ago

aksar9211 commented 2 years ago

Valerii Tereshchenko, I am using object comparer in my project. I used to list out the ignore member before comparison, but In several cases, there are nested parent-child models that go into the loop recursively and result in StackOverflowException. Also instead of excluding the member at the comparer site, It is more useful for us to specify it at the property and field. So, I am proposing the above solution for this issue. Please consider adding it to the live project.

Usage:

[Comparison(ComparisonStatus.ExcludeFromComparison)]
public ObservableCollection <MyClass> myObj{get; set;}

[Comparison(ComparisonStatus.ExcludeFromComparison)]
public MyClass parent{get; set;}
aksar9211 commented 2 years ago

As per your suggestions, I have removed the ComparisonStatus enum class and renamed the ComparisonAttribute to IgnoreInComparisonAttribute. I have also updated the unit testes. Please review again.

aksar9211 commented 2 years ago

Yes. I did. All the tests passed except one: File: ComparerGenericEnumerableTests.cs Line no.:550 Assert.AreEqual(DifferenceTypes.MissedElementInFirstObject, differences.First().DifferenceType);

the difference type is: DifferenceTypes.NumberOfElementsMismatch

This test is failing in the original project as well.

ValeraT1982 commented 2 years ago

Thanks for your contribution

aksar9211 commented 2 years ago

Thank you for merging the code. How to get the nuget package for the same?

ValeraT1982 commented 2 years ago

Currently the only option is to download the source code. I'm going to release next version within couple of month.

swinslade commented 1 year ago

Hi, I downloaded and built the source back in June 2022 just so I could use the [IgnoreInComparison] attribute (which is working perfectly in my project), is there any chance of a new release (nuget package) for these changes in the near future?

Thanks for the great work on this project!

ValeraT1982 commented 1 year ago

Still working on it. Sorry. A lot of work.