Created
May 14, 2018 15:18
-
-
Save mzabsky/fd419593ff59a03dc1e1d53d38ff4c74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyAttribute : Attribute { | |
public string Name {get;} | |
public MyAttribute(string name) | |
{ | |
this.Name = name; | |
} | |
} | |
public enum TestEnum { | |
[My("Aa")] A = 3, | |
[My("Be")] B = 2, | |
[My("Ce")] C = 1 | |
} | |
void Main() | |
{ | |
var type = typeof(TestEnum); | |
var values = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static); | |
var info = values.Select(field => | |
{ | |
return new { field.Name, Value = (int)field.GetValue(null), Localization = field.GetCustomAttribute<MyAttribute>().Name }; | |
}); | |
} | |
/* | |
Vraci: | |
A 3 Aa | |
B 2 Be | |
C 1 Ce | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment