In the project, I have an external enumeration (generated from a service link). Therefore, I cannot change the values of the enumeration.
How can I effectively compare these enum values with each other?
Here is a listing example
public enum Values { A, B, C, D, E, F, G, H }
And the sort order I want them is not the same (something like F, H, A, C, B, ...)
Now I have an extension method with some comparisons. (with another listing with the order I want)
public static int CompareTo(this Values x, Values y) { var orderedX = GetOrderedValues(x); var orderedY = GetOrderedValues(y); return orderedX.CompareTo(orderedY); } internal enum ValuesOrdered { F = 0, H = 1, C = 2, D = 3, B = 4, A = 5, E = 6, G = 7 } internal static ValuesOrdered GetOrderedValues(this Values x) { switch (x) { case Values.A: { return ValuesOrdered.A; }
Could this be achieved more efficiently?