Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Enum.
- GetValues(typeof(CurrencyId)).
- Cast<CurrencyId>().
- Where(c => c != CurrencyId.UNSUPPORTED).
- Select(c => new
- {
- CurrencyId = c,
- SortId = c.
- GetType().
- GetField(c.ToString()).
- GetCustomAttributes(
- typeof(CurrencySortAttribute), false).
- Cast<CurrencySortAttribute>().
- Take(1).
- Select(a => a.SortId).
- DefaultIfEmpty(int.MaxValue).
- Single()
- }).
- OrderBy(a => a.SortId).
- Select(a => a.CurrencyId).
- ToArray();
- public enum CurrencyId
- {
- [CurrencySortAttribute(1)]
- USD = 840,
- [CurrencySortAttribute(2)]
- RUR = 643,
- [CurrencySortAttribute(3)]
- UAH = 980,
- [CurrencySortAttribute(4)]
- EUR = 978,
- [CurrencySortAttribute(5)]
- KZT = 398,
- UNSUPPORTED = 0
- }
- [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
- public class CurrencySortAttribute : Attribute
- {
- public CurrencySortAttribute(int sortId)
- {
- this.SortId = sortId;
- }
- public int SortId { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement