// <copyright file="FolderComparer.cs" company="GoalBook"> // Copyright © 2009 Mark Brownsword. All rights reserved. // This source code and supporting files are licensed under The Code Project // Open License (CPOL) as detailed at http://www.codeproject.com/info/cpol10.aspx. // </copyright> namespace GoalBook.Infrastructure.Comparers { using System; using System.Collections; using GoalBook.Infrastructure.ObjectModel; /// <summary> /// Folder Comparer. /// </summary> public class FolderComparer : IComparer { /// <summary> /// Declaration for FolderList. /// </summary> private FolderList folders; /// <summary> /// Initializes a new instance of the FolderComparer class. /// </summary> /// <param name="folders">list of folders</param> public FolderComparer(FolderList folders) { this.folders = folders; } /// <summary> /// Compare implementation. /// </summary> /// <param name="x">x parameter</param> /// <param name="y">y parameter</param> /// <returns> /// Value Condition /// Less than zero x is less than y /// Zero x equals y /// Greater than zero x is greater than y /// </returns> public int Compare(object x, object y) { if (x == y) { return 0; } if (x == null) { return -1; } if (y == null) { return 1; } Folder t1 = this.GetFolder(x.ToString()); Folder t2 = this.GetFolder(y.ToString()); if (t1 == null) { return -1; } else if (t2 == null) { return 1; } if (t1.Order < t2.Order) { return -1; } else if (t1.Order > t2.Order) { return 1; } return 0; } /// <summary> /// Get Folder. /// </summary> /// <param name="title">title parameter</param> /// <returns>Folder instance</returns> private Folder GetFolder(string title) { foreach (Folder folder in this.folders) { if (folder.Title == title) { return folder; } } return null; } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)