Ignoring The Order
From Compare .NET Objects
| Compare .NET Objects | |
| Ignoring The Order | |
| Send Feedback | |
| Using Compare .NET Objects > Ignoring The Order |
Glossary Item Box
Ignoring the Order
Sometimes lists, arrays, and dictionaries are equal to each other but they are in a different order. The Config.IgnoreCollectionOrder property can be used to compare lists that are not only out of order but also of different lengths. There is a huge performance decrease when Ignoring the Collection Order. This may be okay if you are comparing a few hundred objects at a time. By default all the simple type properties are used as a key for an object. To minimize the perforance impact, define a Config.CollectionMatchingSpec. This defines the key for the object.
Example:
CompareLogic logic = new CompareLogic();
logic.Config.IgnoreCollectionOrder = true;
var spec = new Dictionary<Type, IEnumerable<string>>();
spec.Add(typeof(Customer), new string[] { "CustomerId" });
logic.Config.CollectionMatchingSpec = spec;