using System.Collections; using System.Linq; using System.Windows.Forms; namespace Ringtoets.Common.Forms.PresentationObjects { /// /// Object that allows for grouping child nodes of instances. /// public class CategoryTreeFolder { /// /// Initializes a new instance of the class. /// /// The name of the category folder. /// The contents of the folder. /// Optional: The category descriptor of the folder. Default: . public CategoryTreeFolder(string name, IList contents, TreeFolderCategory category = TreeFolderCategory.General) { Name = name; Contents = contents.OfType().ToArray(); Category = category; } /// /// Gets the name of the folder. /// public string Name { get; private set; } /// /// Gets the contents of the folder. /// public IList Contents { get; private set; } /// /// Gets the category of the folder. /// public TreeFolderCategory Category { get; private set; } public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) { return false; } if (ReferenceEquals(this, obj)) { return true; } if (obj.GetType() != GetType()) { return false; } return Equals((CategoryTreeFolder) obj); } public override int GetHashCode() { return Contents.Cast().Aggregate(Name != null ? Name.GetHashCode() : 0, (current, content) => current ^ content.GetHashCode()); } private bool Equals(CategoryTreeFolder other) { if (Name != other.Name) { return false; } if (Contents.Count != other.Contents.Count) { return false; } for (var i = 0; i < Contents.Count; i++) { if (!Contents[i].Equals(other.Contents[i])) { return false; } } return true; } } }