Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1452 | chris | 1 | #region License |
| 2 | // |
||
| 3 | // The Open Toolkit Library License |
||
| 4 | // |
||
| 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. |
||
| 6 | // |
||
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
||
| 8 | // of this software and associated documentation files (the "Software"), to deal |
||
| 9 | // in the Software without restriction, including without limitation the rights to |
||
| 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
||
| 11 | // the Software, and to permit persons to whom the Software is furnished to do |
||
| 12 | // so, subject to the following conditions: |
||
| 13 | // |
||
| 14 | // The above copyright notice and this permission notice shall be included in all |
||
| 15 | // copies or substantial portions of the Software. |
||
| 16 | // |
||
| 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||
| 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
||
| 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
||
| 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
||
| 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
||
| 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||
| 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
||
| 24 | // OTHER DEALINGS IN THE SOFTWARE. |
||
| 25 | // |
||
| 26 | #endregion |
||
| 27 | |||
| 28 | using System; |
||
| 29 | using System.Collections.Generic; |
||
| 30 | using System.Text; |
||
| 31 | using System.Windows.Forms; |
||
| 32 | using System.Collections; |
||
| 33 | |||
| 34 | namespace Examples |
||
| 35 | { |
||
| 36 | class SamplesTreeViewSorter : IComparer<TreeNode>, IComparer |
||
| 37 | { |
||
| 38 | #region IComparer<TreeNode> Members |
||
| 39 | |||
| 40 | public int Compare(TreeNode x, TreeNode y) |
||
| 41 | { |
||
| 42 | ExampleInfo x_info = x.Tag as ExampleInfo; |
||
| 43 | ExampleInfo y_info = y.Tag as ExampleInfo; |
||
| 44 | if (x_info == null || y_info == null) |
||
| 45 | { |
||
| 46 | return x.Text.CompareTo(y.Text); |
||
| 47 | } |
||
| 48 | else |
||
| 49 | { |
||
| 50 | int result = x_info.Attribute.Category.CompareTo(y_info.Attribute.Category); |
||
| 51 | if (result == 0) |
||
| 52 | result = x_info.Attribute.Subcategory.CompareTo(y_info.Attribute.Subcategory); |
||
| 53 | if (result == 0) |
||
| 54 | result = x_info.Attribute.Difficulty.CompareTo(y_info.Attribute.Difficulty); |
||
| 55 | if (result == 0) |
||
| 56 | result = x_info.Attribute.Title.CompareTo(y_info.Attribute.Title); |
||
| 57 | |||
| 58 | return result; |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | #endregion |
||
| 63 | |||
| 64 | #region IComparer Members |
||
| 65 | |||
| 66 | public int Compare(object x, object y) |
||
| 67 | { |
||
| 68 | if (x is TreeNode && y is TreeNode) |
||
| 69 | return Compare(x as TreeNode, y as TreeNode); |
||
| 70 | else |
||
| 71 | return 0; |
||
| 72 | } |
||
| 73 | |||
| 74 | #endregion |
||
| 75 | } |
||
| 76 | } |