Here's an example of the architecture approach I favorited as for now:
public abstract class CollectionComparer {
public virtual SetEqual(IEnumerable enum1, IEnumerable enum2) {
if(enum1== null && enum2== null)
return true;
if(enum1== null && !(enum2== null))
return false;
if(!(enum1== null) && enum2== null)
return false;
if(enum1.GetType().DeclaringType != enum2.GetType().DeclaringType)
return false;
var col1 = (from e in enum1 select e).ToList()
var col2 = (from e in enum2 select e).ToList()
if(col1.Count != col2.Count)
return false;
foreach (element in col1)
if(!col2.Contains(element))
return false;
foreach (element in col2)
if(!col1.Contains(element))
return false;
return true;
}
}
public interface IProduct {
...
}
public interface IOrder {
...
ICustomer Customer { get; }
ICollection<IProduct> Products { get; }
}
public interface ICustomer {
...
ICollection<IOrder> Orders { get; }
}
public internal Order : CollectionComparer, IOrder {
#region IOrder interface implementation
...
#endregion
}
public internal Customer : CollectionComparer, ICustomer {
#region ICustomer interface implementation
...
#endregion
}
Would this CollectionComparer abstract class approach be considered a good practice for collection comparison for an equivalent to object.Equals() applied to a collections?