-
-
Save srakowski/4d54139ca06427878bcf7b39dc2f38d5 to your computer and use it in GitHub Desktop.
Enumerate Class Constants
This file contains hidden or 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 static class MagicStrings | |
{ | |
public const string Potato = "Potato"; | |
public const string Tomato = "Tomato"; | |
private static string[] _strings; | |
public static string[] Strings | |
{ | |
get | |
{ | |
if (_strings != null) return _strings; | |
_strings = typeof(MagicStrings).GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy) | |
.Where(f => f.IsLiteral && !f.IsInitOnly && f.FieldType == typeof(string)) | |
.Select(f => (string)f.GetValue(null)).ToArray(); | |
return _strings; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment