1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing.Model
7 using System.Collections;
8 using System.Collections.Generic;
9 using System.Activities.Presentation.PropertyEditing;
12 // Compares PropertyEntry instances based on their PropertyOrder tokens
13 // as well as their DisplayNames
15 internal class PropertyEntryPropertyOrderComparer : IComparer, IComparer<PropertyEntry>
18 private static readonly PropertyOrder DefaultOrder = PropertyOrder.Default;
19 private static PropertyEntryPropertyOrderComparer _instance;
22 // Gets a singleton instance of this class
24 public static PropertyEntryPropertyOrderComparer Instance
27 if (_instance == null)
29 _instance = new PropertyEntryPropertyOrderComparer();
37 // Compares two instances of PropertyEntry class, using both
38 // PropertyOrder and DisplayName to cast its vote.
40 // <param name="x">Left side</param>
41 // <param name="y">Right side</param>
42 // <returns>Comparison result</returns>
43 public int Compare(object x, object y)
45 return CompareCore(x, y);
49 // Compares two instances of PropertyEntry class, using both
50 // PropertyOrder and DisplayName to cast its vote.
51 // Same method, different signature.
53 // <param name="x">Left</param>
54 // <param name="y">Right</param>
55 // <param name="x">Left side</param>
56 // <param name="y">Right side</param>
57 // <returns>Comparison result</returns>
58 public int Compare(PropertyEntry x, PropertyEntry y)
60 return CompareCore(x, y);
63 private static int CompareCore(object x, object y)
65 ModelPropertyEntry j = x as ModelPropertyEntry;
66 ModelPropertyEntry k = y as ModelPropertyEntry;
68 if (j == null && k == null)
81 PropertyOrder a = j.PropertyOrder ?? DefaultOrder;
82 PropertyOrder b = k.PropertyOrder ?? DefaultOrder;
84 int result = a.CompareTo(b);
86 return result != 0 ? result : string.Compare(j.DisplayName, k.DisplayName, StringComparison.CurrentCulture);