2

I have a class with many properties, some of them are lists of custom types. I need to compare two instances of this class, and get a list of properties that aren't equal in them.

I designed it with custom attributes (for the relevant properties that I want to include in the comparison), and using the IEquatable, but for the lists I ran into problems. I was going to use SequenceEqual but it requires the type of the list (IEnumerable<SomeType>), which I don't have and don't know how to set. I'm aware of the GetElementType and GetGenericArguments methods but I can't use them inside IEnumerable<> to make the SequenceEqual work.

I'm looking for the best design for this scenario, and also code examples of how to actually do it.

yellowblood
  • 1,604
  • 2
  • 17
  • 32

1 Answers1

4

This Codeplex project performs a deep compare of any two .NET objects using reflection: http://comparenetobjects.codeplex.com/

Project Description

Perform a deep compare of any two .NET objects using reflection. Shows the differences between the two objects.

Compatiblity

Compatible with .NET Framework 3.5 and higher. New in 2.0, portable Class Library version works with .NET 4.0+, Silverlight 5+, Windows Phone 8+, Windows RT 8+, Xamarin iOS, and Xamarin Droid

NuGet Package

http://www.nuget.org/packages/CompareNETObjects

Community
  • 1
  • 1
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501