Advertisement
Guest User

Untitled

a guest
Aug 6th, 2014
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. Enum.
  2.     GetValues(typeof(CurrencyId)).
  3.     Cast<CurrencyId>().
  4.     Where(c => c != CurrencyId.UNSUPPORTED).
  5.     Select(c => new
  6.     {
  7.         CurrencyId = c,
  8.         SortId = c.
  9.             GetType().
  10.             GetField(c.ToString()).
  11.             GetCustomAttributes(
  12.                 typeof(CurrencySortAttribute), false).
  13.             Cast<CurrencySortAttribute>().
  14.             Take(1).
  15.             Select(a => a.SortId).
  16.             DefaultIfEmpty(int.MaxValue).
  17.             Single()
  18.     }).
  19.     OrderBy(a => a.SortId).
  20.     Select(a => a.CurrencyId).
  21.     ToArray();
  22.  
  23. public enum CurrencyId
  24. {
  25.     [CurrencySortAttribute(1)]
  26.     USD = 840,
  27.  
  28.     [CurrencySortAttribute(2)]
  29.     RUR = 643,
  30.  
  31.     [CurrencySortAttribute(3)]
  32.     UAH = 980,
  33.  
  34.     [CurrencySortAttribute(4)]
  35.     EUR = 978,
  36.  
  37.     [CurrencySortAttribute(5)]
  38.     KZT = 398,
  39.  
  40.     UNSUPPORTED = 0
  41. }
  42.  
  43. [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
  44. public class CurrencySortAttribute : Attribute
  45. {
  46.     public CurrencySortAttribute(int sortId)
  47.     {
  48.         this.SortId = sortId;
  49.     }
  50.  
  51.     public int SortId { get; set; }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement